Eureka is a product of Netflix's open source offering service registration and discovery, which provides complete services registry and service discovery implementations. is also one of the most important and core components of the Springcloud system.
Background Information Service Center
The service center, also known as the Registration Center, manages various service functions including service registration, discovery, fusing, loading, downgrading, etc., such as Dubbo admin backstage functions.
With the service center call relationship what will change, draw a few diagrams to help understand
Project A calls Project B
Normal call to project a request item B
With the service center, any service can not be removed directly, all need to call through the service center
Project A calls project B, and Project B invokes Project C
The step that is called at this time is two steps: The first step, project a first requests the Project B server from the service center, and then project B requests the Project C service from the service center.
The above project is just two or three simple calls between each other, but if the project is more than 20 30, at the end of 15, our distributed project reached more than 20, draw a picture to describe the relationship between the dozens of items are all lines, any one of the project changes, Will implicate several projects followed by reboots, big trouble and error prone. Service Center to get services you do not need to focus on the project IP address you call, consisting of several servers, each time directly to the service center to get the service can be used to call both.
As various services are registered to the service center, there are many advanced functional conditions to do. For example, several services provide the same service to do a balanced load, the monitoring server calls the success rate to do the fuse, remove the fault point in the service list, monitor the service invocation time to set different weights for different servers, and so on.
Before I say Eureka, I'll gossip about Netflix.
Netflix
The following introduction from the Baidu Encyclopedia:
Netflix is an American company that offers internet streaming in the United States, Canada, custom DVDs, and Blu-ray discs online rental business. The company was founded in 1997 and is headquartered in California State, and began its subscription service in 1999. In 2009, the company was able to provide up to 100,000 DVD films and 10 million subscribers. On February 25, 2007, Netflix announced that it had sold its 1 billionth DVD. In his report, Netflix's online film sales accounted for 45% of the total sales of U.S. users on-line movies in 2011.
When I first saw the word, it was at the beginning of a variety of American dramas or films, and the typical American drama that Netflix photographed was "the House of Cards," "The Drug Lords," and "Strange things." Later, when studying Springcloud, I discovered Netflix, wondering if they were the same company, checking that the email suffix on GitHub was really the same company, in fact Springcloud's microservices were based on Netflix's open source products.
Netflix's open source framework component has been proven in Netflix's massively distributed microservices environment for many years, and is gradually being accepted by the community as the standard component for structuring the microservices framework. Spring Cloud Open source, based primarily on the further encapsulation of the Netflix open source components, makes it easy for spring developers to build a microservices infrastructure. For companies that are planning to build a microservices framework, leveraging or referencing Netflix's open source microservices components (or spring Cloud) on the basis of the necessary enterprise customization is undoubtedly a shortcut to the MicroServices architecture.
Eureka
According to the official introduction:
Eureka is a REST (representational state Transfer) based service, that's primarily used in the AWS cloud for locating serv ICES for the purpose of load balancing and failover of middle-tier servers.
Eureka is a REST-based service that is primarily used in the AWS cloud to locate services for load balancing and failover of middle-tier servers.
Spring Cloud encapsulates the Eureka module developed by Netflix to enable service registration and discovery. The Eureka uses the C-s design architecture. Eureka server serves as the service registration feature for servers that are service registries. While other microservices in the system, use the Eureka client to connect to the Eureka Server and maintain a heartbeat connection. This allows the maintenance personnel of the system to monitor the operation of each micro-service in the system through Eureka Server. Some other Spring Cloud modules, such as Zuul, can be used by Eureka Server to discover other microservices in the system and execute related logic.
The Eureka consists of two components: the Eureka server and the Eureka client. The Eureka server serves as the service registration server. The Eureka client is a Java client that simplifies the interaction with the server, acts as a polling load balancer, and provides failover support for the service. Netflix uses additional clients in its production environment, which provides weighted load balancing based on traffic, resource utilization, and Error state.
Use a picture to recognize the following:
Briefly describes the basic architecture of Eureka, consisting of 3 characters:
1. Eureka Server
- Provide service registration and discovery
2. Service Provider
- Service Provider
- Registering their services with Eureka so that service consumers can find
3. Service Consumer
- Service Consumer
- Get a list of registered services from Eureka so you can consume services
Case Practice Eureka Server
Spring Cloud has helped me implement the service registry, and we just need a few simple steps to get it done.
1. Add Dependency in Pom
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
2. Add annotations in the startup code @EnableEurekaServer
@SpringBootApplication@EnableEurekaServerpublic class SpringCloudEurekaApplication {public static void main(String[] args) {SpringApplication.run(SpringCloudEurekaApplication.class, args);}}
3. Configuration files
Under the default settings, the service registry will also try to register itself as a client, so we need to disable its client registration behavior, application.properties
Adding the following configuration:
spring.application.name=spring-cloud-eurekaserver.port=8000eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
eureka.client.register-with-eureka
: Indicates whether to register itself to Eureka Server, which is true by default.
eureka.client.fetch-registry
: Indicates whether to obtain registration information from Eureka Server, which is true by default.
eureka.client.serviceUrl.defaultZone
: Sets the address to interact with Eureka Server, which is dependent on the query service and registration service. The default is Http://localhost:8761/eureka; multiple addresses can be used, delimited.
After starting the project, visit: http://localhost:8000/, you can see the following page, which has not found any services
Cluster
Registry such a critical service, if it is a single point, encounter a failure is devastating. In a distributed system, the service registry is the most important basic part and should always be in a state of service. In order to maintain its availability, the use of clusters is a good solution. Eureka enables highly available deployments by registering with each other, so we only need to configure the Eureke server with other available serviceurl to enable a highly available deployment.
Two-node Registration center
For the first time, we try to build a two-node registry.
1, create application-peer1.properties, as the Peer1 Service center configuration, and will serviceurl point to Peer2
spring.application.name=spring-cloud-eurekaserver.port=8000eureka.instance.hostname=peer1eureka.client.serviceUrl.defaultZone=http://peer2:8001/eureka/
2, create application-peer2.properties, as the Peer2 Service center configuration, and will serviceurl point to Peer1
spring.application.name=spring-cloud-eurekaserver.port=8001eureka.instance.hostname=peer2eureka.client.serviceUrl.defaultZone=http://peer1:8000/eureka/
3. Host Conversion
Add the following configuration to the Hosts file
127.0.0.1 peer1 127.0.0.1 peer2
4, Packaging start
Execute the following command in turn
#打包mvn clean package# 分别以peer1和peeer2 配置信息启动eurekajava -jar spring-cloud-eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1java -jar spring-cloud-eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2
After the startup is complete, the browser enters: http://localhost:8000/
It can be seen from the graph that Peer1 's registry DS replicas already has peer2 related configuration information and appears in Available-replicas. We manually stop Peer2 to see that Peer2 will move to the Unavailable-replicas column, indicating that Peer2 is not available.
The configuration to this two-node is complete.
Eureka Cluster Usage
In the production we may need three or more than three registries to ensure the stability of the service, the principle of configuration is actually the same, the registration center points to other registries respectively. This only describes the configuration of the three clusters, in fact, and the two-node registry similar to each of the registration center points to another two nodes can be configured using APPLICATION.YML.
APPLICATION.YML configuration details are as follows:
---spring: application: name: spring-cloud-eureka profiles: peer1server: port: 8000eureka: instance: hostname: peer1 client: serviceUrl: defaultZone: http://peer2:8001/eureka/,http://peer3:8002/eureka/---spring: application: name: spring-cloud-eureka profiles: peer2server: port: 8001eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8000/eureka/,http://peer3:8002/eureka/---spring: application: name: spring-cloud-eureka profiles: peer3server: port: 8002eureka: instance: hostname: peer3 client: serviceUrl: defaultZone: http://peer1:8000/eureka/,http://peer2:8001/eureka/
Start the Eureka registry with the configuration parameters of Peer1, Peer2, and Peer3 respectively.
java -jar spring-cloud-eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1java -jar spring-cloud-eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer2java -jar spring-cloud-eureka-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer3
After the startup is complete, the browser enters: http://localhost:8000/
You can see the information about Peer2 and Peer3 in Peer1. The Eureka Cluster has also been completed
Sample Code-github
Sample code-Cloud Code
Reference:
Spring Cloud Building MicroServices Architecture (vi) High-availability service registry
Peer Awareness
A pure Smile
Source: http://www.ityouknow.com/
Copyright belongs to the author, please specify the source of the reprint
Springcloud (ii): Registration center Eureka