First, service governance: Spring Cloud Eureka

Source: Internet
Author: User

Core content:

    1. Build a Service registration center
    2. Service Registration in service discovery
    3. Eureka's Infrastructure
    4. The service governance mechanism of Eureka
    5. Configuration of the Eureka

Service governance: Mainly used to realize the automation registration and discovery of each micro-service instance

Service registration: In the service governance framework, a registry is typically built, and each service unit registers its own service with the registry, informs the registry of some information such as the host and port number, version number, communication protocol, and so on, and the registry organizes the list of services by service name.

eg

In addition, the service registry needs to monitor the availability of services in the list by heartbeat, and if it is not available, it needs to be kicked out of the service list.

Service discovery: Because of the service governance framework, calls between services are no longer implemented through the development of specific instance addresses, but are implemented by initiating request transfers to the service name.

Step: 1, call the direction service registry to get an instance list of all services

2. Polling out one of the list for service invocation (load Balancing)

Build a Service Registration center:

1. Add Dependencies:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>--springboot version and Springcloud version need pairing yo
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

2. Start a service registry with @enableeurekaserver annotations to provide dialogue for other applications

3. Add Configuration
server.port=1111
Eureka.instance.hostname=localhost
Eureka.client.register-with-eureka=false--Because the app is a registry, set to False, the representative does not want the registry to register itself
Eureka.client.fetch-registry=false-Because the registry is responsible for maintaining the service instance, it does not need to retrieve the service, so it is also set to False
eureka.client.service-url.defaultzone=http://${eureka.instance.hostname}:${server.port}/eureka/
4. Start Project Access: http://localhost:1111

Registered service Provider
Add a springboot application to Eureka's service governance system
1. Create a new module
2. Join
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
3. Add @enableeurekaclient annotations on the startup class
4. Adding configuration Files
Spring.application.name=hello-service
eureka.client.service-url.defaultzone=http://localhost:1111/eureka/

High-Availability Registration center
In Eureka's service governance design, all nodes are both service providers and service consumers, and service registries are no exception.
The high availability of Eureka server is actually the service you want to register yourself with other service registries (registering with each other)
Build:

After you have multiple registries, modify the service providers and service consumers:
eureka.client.service-url.defaultzone=http://localhost:1111/eureka/,http://localhost:1112/eureka/
Now that you have a service registry and a service consumer, you now need a service provider. Service discovery tasks are done by Eureka clients, and service consumption tasks are done by the Ribbon
Basically consistent with the original hello-service, adding in dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
Add Resttemplate to the configuration class and add @loadbalanced user load Balancer
Finally, call the service inside the Hello-service
@Autowired     Private resttemplate resttemplate;    @RequestMapping ("/ribbon-consumer")    public  String helloconsumer () {          return resttemplate.getforentity ("Http://hello-service/hello", String.  Class). GetBody ();    }

Start Ribbon-consumer, request two times/ribbon-consumer, you can see print information at once on both consoles

The callee information can also be seen in Ribbon-consumer

First, service governance: Spring Cloud Eureka

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.