Spring Cloud micro-Service monomer deployment Eureka Server-side client building __spring

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.