In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the functions of spring-cloud". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of spring-cloud"?
Spring cloud research summary microservice startup
Spring cloud follows the startup mode of spring boot.
For general service
@ EnableDiscoveryClient
@ SpringBootApplication
Registration center
Service registration
Spring cloud microservices need to have a registration environment eureka-server, and each service will be registered with the service.
The configuration is as follows
Maven introduction of eureka-server
Application.properties profile
By default, the service registry will also try to register itself as a client, so we need to disable its client registration behavior (single point registry, post-cluster deployment will be different)
Producer
Producers need to publish services to the registry
Register with the registry:
Eureka.client.serviceUrl.defaultZone= http://localhost:7070/eureka/
Consumer
Consumer invokes service
Define the interface, and define the service-B in the form of an interface. This service-B is the service name defined by the microservice in the registry.
Load balancing strategy
The same service is registered with the registry with the same id and different ports, and when invoked, spring-cloud implements service scheduling through ribbon. Ribbon will call the service under the load first through the load of the service.
Registry cluster
In the form of mutual registration, spring cloud has the ability to deliver services, so that the registry and cluster configuration can be implemented.
Configuration 1:
Suppose we have three registries, and we each point the peer1, peer2, and peer3 serviceUrl to the other two nodes. In other words, peer1, peer2 and peer3 are registered in pairs. Start the three service registries, point the serviceUrl of compute-service to peer1 and start it, and you can achieve the clustering effect shown in the following figure.
Configuration two
Let's still assume that we have three registries, and we point the serviceUrl of peer1 to peer2,peer2 and the point of peer3,peer3 to peer1, and then peer1, peer2, and peer3 form a ring through one-way edges. Starting peer1, peer2, peer3 and visiting the information page respectively, we can find the following rule: peer1 becomes the sharding node of peer2, peer2 becomes the sharding node of peer3, and peer3 becomes the sharding node of peer1. Then point the serviceUrl of compute-service to peer1 and start it. If you don't visit the information pages of peer1, peer2 and peer3, you can find that compute-service is synchronized by peer2 and peer3, so one-way side can also propagate and synchronize services. At this point, we disconnect the peer2 and see that the compute-service in the peer3 disappears. Turn on peer2 and disconnect peer3, and you can see that peer2 can still synchronize to compute-service. Therefore, we can draw a conclusion that the propagation and synchronization of Eureka Server is directional.
Pairwise registration can achieve the effect of complete equivalence of nodes in the cluster and achieve the highest availability cluster. Any registry failure will not affect service registration and discovery that Eureka Server has a unilateral service propagation and synchronization mechanism. In some cases with restrictions on service discovery, this mechanism can be used for one-way control of service registration and discovery.
Circuit breaker
1. Circuit breaker mechanism
The circuit breaker is easy to understand. When the number of Hystrix Command requests for back-end service failures exceeds a certain percentage (default 50%), the circuit breaker will switch to the open state (Open). At this point, all requests will fail directly and will not be sent to the back-end service. After keeping the circuit breaker in the open state for a period of time (default 5 seconds), the circuit breaker automatically switches to the semi-open state (HALF-OPEN). At this time, the return of the next request will be judged, and if the request is successful, the circuit breaker will switch back to the closed-circuit state (CLOSED), otherwise it will switch back to the open-circuit state (OPEN). Hystrix circuit breaker is like a fuse in our home circuit. Once the back-end service is not available, the circuit breaker will directly cut off the request chain to avoid sending a large number of invalid requests to affect the system throughput, and the circuit breaker has the ability to self-detect and recover.
2.Fallback
Fallback is equivalent to a downgrade operation. For query operations, we can implement a fallback method. When an exception occurs in the request back-end service, we can use the value returned by the fallback method. The return value of the fallback method is usually the default value set or from the cache.
3. Resource isolation
In Hystrix, resource isolation is mainly achieved through thread pool. Usually when we use it, we divide multiple thread pools according to the remote service invoked. For example, the Command that calls the product service is put into the A thread pool, and the Command that invokes the account service is put into the B thread pool. The main advantage of this is that the operating environment is isolated. In this way, even if the code that invokes the service exists bug or other reasons cause the thread pool to be exhausted, it will not affect other services of the system. But the cost is that maintaining multiple thread pools will bring additional performance overhead to the system. If you have strict performance requirements and are sure that the client code that invokes the service will not have a problem, you can use Hystrix's signal mode (Semaphores) to isolate resources.
Service asynchronous invocation
Asynchronous invocation invokes the message without waiting for the message to return.
1. Define a consumer service as an asynchronously callable service
Define the method as asynchronous method
To meet the above two points, the asynchronous operation is implemented when the consumer service is invoked.
Distributed deployment profile management
When there are more and more micro-services, the configuration files of the system will be more and more, and the configuration file information will be managed centrally through the config-server provided by spring cloud. Config-server stores configuration files via git by default. Remote acquisition is supported. Take remote git configuration repository as an example
1. Create a git configuration repository in oschina that contains various configuration files, including lovnx-dev.properties,lovnx-test.properties.
two。 Create a config-server service
Set up remote warehouse information
Normal service invocation configuration service
In this way, the lovnx-dev.properties profile information is obtained
Spring cloud monitoring
The monitoring function of the application is very important for distributed systems. If you compare the distributed system to the whole social system. Then each service corresponds to the specific service institutions in the society, such as banks, schools, supermarkets, etc., then monitoring is similar to police stations and hospitals, so its importance is obvious. Here, the deployment and operation of the monitoring service is different from the circuit breaker monitoring, it is mainly about the monitoring service and the indicators of the server.
Thank you for your reading, the above is the content of "what is the role of spring-cloud". After the study of this article, I believe you have a deeper understanding of the role of spring-cloud, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.