I. Overview
In the previous chapter, we have seen that the microserver-user microservice has been registered in the Eureka server. In this article, we will explain how the Eureka client is registered in the Eureka Server. Again, the author has limited ability and insufficient expression ability. I will give a conceptual explanation. Friends who want to understand the concept can check it on Baidu or the official website to understand it by themselves. At the same time, take care of newcomers and friends as much as possible, and teach everyone how to learn a technology from the official website. If there is any mistake, I hope you will point out common progress.
Second, the directory structure
Careful friends may have found that the directory structure here has become a multi-module project. The api needs to integrate Spring Cloud OpenFeign for inter-service calls. Friends who do not create Maven multi-module projects can read the blog written by the author a long time ago. I won't go into too much detail here.
3. Build the Eureka client
1) First of all, you still need to see how the official documentation explains it. From the documentation, we need to introduce Eureka-client related jar packages for the project.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
2) Since the microserver-user service is a web project, the corresponding web package needs to be added.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
3) Understand the simple configuration given by the official documentation
4) Since our Eureka Server port requires user authentication, we need to make some small changes on this basis
eureka: instance: prefer-ip-address: true instance-id: ${spring.application.name}(${spring.cloud.client.ip-address}:${server.port}) lease-renewal-interval-in-seconds: 10 client: service-url: defaultZone: http://user:password123@localhost:8761/eureka/
I saw a new attribute lease-renewal-interval-in-seconds. The previous chapter has explained how to view the configuration information from the official website. The general meaning of the official website is that the Eureka client will send a heartbeat to the server in 30 seconds by default. , tell the server that I'm still alive~~~ ^_^ Big brother~ don't kill me, as our big brother, the default is 90 seconds for the server to raise the butcher's knife if it does not receive the renewal request from the client. Of course these are all configurable
Friends who don't know can study it
Finally, add @EnableEurekaClient on the startup class. Note: This annotation can be omitted in Edgware and later versions.