In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to build an Eureka service registry in SpringCloud. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
One: introduction to Eureka
Eureka, similar to Consul and Zookeeper, is a component of user service discovery and service registration, which was initially mainly used in Amazon's cloud computing service platform AWS. Eureka is divided into EurekaServer (service registry) and EurekaClient (client).
Advantages of Eureka
1: completely open source, and after three years of iteration, performance and functionality are very stable.
2: it is the officially recommended registry of SpringCloud, which can be perfectly interfaced with other components of SpringCloud.
3:Eureka can cooperate with Ribbon, Hystrix, Zuul and other components to quickly complete the service registry, and these components are called Netfilx OOS components, which are integrated by SpringCloud. They are the core service components and basic components of SpringCloud.
Second: set up the first service registration center
Talking is boolshit, just look at the code!
Parent project pom.xml
Com.calvin.cloudcloud_day01pom1.0-SNAPSHOT eureka-server eureka-client org.springframework.boot spring-boot-starter-parent 1.5.3.RELEASE UTF-8 UTF-8 1.8 org.springframework.cloud spring-cloud-dependencies Dalston.SR4 pom import
Use SpringInitializr to create two child Module, eureka-server and eureka-client
Eureka-server/pom.xml
Cloud_day01 com.calvin.cloud 1.0-SNAPSHOT4.0.0eureka-server org.springframework.cloud spring-cloud-starter-eureka-server org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
Eureka-server/EurekaServerApplication.java
/ * EurekaServer launch class * @ author Calvin * @ date 2019-07-29 * / @ SpringBootApplication@EnableEurekaServerpublic class ServerApplication {public static void main (String [] args) {SpringApplication.run (ServerApplication.class);}}
Eureka-server/application.yml
Server: port: 8080eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
Start EurekaServerApplication.main (), and the browser accesses http://localhost:8080/eureka, which shows that no services are available to register.
No instances available
Let's write another EurekaClient.
Eureka-client/pom.xml
Cloud_day01 com.calvin.cloud 1.0-SNAPSHOT 4.0.0 eureka-client org.springframework.cloud spring-cloud-starter-eureka org.springframework.boot spring-boot-starter-test test org.springframework.boot Spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin
Eureka-client/application.yml
Server: port: 8081spring: application: name: my_eureka_clienteureka: client: service-url: defaultZone: http://localhost:8080/eureka/
Eureka-client/ClientApplication.java
/ * Client test launch class * @ author Calvin * @ date 2019-09-29 * / @ SpringBootApplication@EnableEurekaClientpublic class ClientApplication {public static void main (String [] args) {SpringApplication.run (ClientApplication.class);}}
Refresh http://localhost:8080/eureka Discovery Service has been registered successfully
Third: Eureka core explores concepts in microservices
1PUR Registermuri-Service Registration
Service registration means that EurekaClient Xiang EurekaServer submits and registers its own service information, including IP address, port, ServiceID and other information. If there is no ServiceId in EurekaClient, the service name is # {spring.application.name} in the configuration file by default.
2RenewMui-Service renewal
By default, EurekaClient sends a heartbeat every 30 seconds for service renewal. Inform EurekaServer that the EurekaClient is still available and has not failed through a service renewal. If EurekaServer does not receive a heartbeat within 90s, EurekaServer will think that the service is dead and will remove the EurekaClient strength from the registration list.
3FetchRegistriesMuffle-get the service registration list information
EurekaClient gets the service registry information from EurekaServer and caches it locally. EurekaClient uses the information in the service registration list to find information about other services for remote invocation.
The registration list information will be updated from the server every 30 seconds. The registration list information returned each time may not match the information cached by EurekaClient. EurekaClient will process the information on its own. If, for some reason, the registration list information does not match in time, EurekaClient will update the information again.
EurekaServer caches all the service registration list information and compresses the entire service list and every other application, and the compressed content is exactly the same as the uncompressed content. EurekaClient and EurekaServer may communicate with each other in JSON and XML data formats. By default, EurekaClient uses JSON format to obtain service registration list information.
4PUR CancelMusi-Service offline
EurekaClient can send an offline request to EurekaServer when the program is closed. After sending the request, the instance information of the client will be deleted from the service information list of EurekaServer. The offline request will not be completed automatically, and the following code DiscoverManager.getInstance () .shutdownComponent () needs to be called when the program is closed.
5VRV EvicationMutual-Service removal
By default, when EurekaClient does not send a heartbeat like EurekaServer for 90 seconds, EurekaServer will assume that the service is no longer available and remove the service instance from the service list information.
High availability service registry
The above architecture describes how Eureka is deployed on Netflix, and it is also the normal deployment and operation of normal Eureka. Each zone has an Eureka cluster, and each zone has at least one Eureka server to handle regional failures.
The service registers with EurekaServer and then sends a heartbeat to renew its lease every 30 seconds. If the client cannot keep its heartbeat, EurekaServer removes the service instance from the server registration list after 90 seconds. Registration and renewal information will be replicated to all EurekaServer nodes in the cluster. EurekaClient from any region can get all the registration list information every 30 seconds and make remote calls. The above information is from the official website: https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance
Four: summary
A brief introduction to Eureka and its advantages and disadvantages
Write the first Eureka registry
Understand the concepts in Eureka and the architecture of highly available registries
Five: summary of problems
The content is relatively simple and there is no in-depth analysis of the concept
There is no cluster building in the code, and there is no test service provider and consumer.
Source code parsing should be added later.
The above is how to build an Eureka service registry in SpringCloud. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.