eureka-client
When the service discovery component is built, how does the Micro service register to the service discovery component? When building a Eureka cluster, how to keep the registry consistent between Eureka-server. This all involves the Eureka-client (Eureka client). The role of Eureka-client to Eureka-server registration information, from the Eureka-server to obtain registry information and so on.
If this is a bit difficult to understand, we can say so. When it comes to monomer deployment Eureka Services, say Eureka-server is a message dealer. So eureka-client is a cell phone. The micro-service has a cell phone that tells the dealer his or her name and contact information, and tells Eureka-server that if someone takes it (eureka-client) to find it (eureka-server), take It (eureka-client) Position to speak out. This is the registration. Of course, micro-service can also use the telephone to obtain other micro-service contact information from the message Merchant (Eureka-server). What's more, the phone (eureka-client) also has the ability to keep contact with other micro-services obtained from the dealer, so that the next time you want to find that micro-service, you don't always have to ask the dealer, after all, the phone bill is for money.
In this way, the phone (eureka-client) is vital, without a mobile phone, there is no micro-service can contact the message dealer (Eureka-server), of course, the message dealers can not provide any information.
So how does a micro-service buy a mobile phone that can be contacted by a word dealer? implementing the Eureka client
To add eureka-client dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-web</artifactid>
</dependency>
<dependency>
<groupId> Org.springframework.cloud</groupid>
<artifactId>spring-cloud-starter-netflix-eureka-client< /artifactid>
</dependency>
Add Annotations to Eurekaclientapplication @enableeurekaclient
Package com.wangguitang.freedom.study.spring.cloud.eureka.client;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
Import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient Public
class Eurekaclientapplication {public
static void Main (string[] args) {
springapplication.run (eurekaclientapplication.class, args);
}
}
Adding a configuration to the configuration file application.yml
Server:
port:8080
Spring:
application:
name:eureka-client
Eureka:
client:
Serviceurl:
Defaultzone:http://localhost:8761/eureka
Start Eureka-clientRight-Class eurekaclientapplication, select Run as–>spring Boot App
GitHub Source
Https://github.com/wang465745776/freedom-study-spring-cloud-parent/tree/master/freedom-study-spring-cloud-eureka-client