Springcloud (3)---Eureka Service registration and Discovery

Source: Internet
Author: User
Eureka Service Registration and Discovery

I. Overview of Eureka 1. Eureka features

(1) Eureka is a rest-based service for locating services to enable mid-tier service discovery and failover in the cloud.

(2) Eureka Supervisor Service Registration and Discovery , in the micro-service, after the two, only need to use the service identifier (= = that the yml file in each service to obtain the service name = =),

You have access to the service and do not need to modify the configuration file for the service call.

(3) Eureka follows the AP principle (High availability, partition fault tolerance)because of the use of a self-protection mechanism so that high availability is ensured.

2, Eureka two major components

Two components :Eureka Server (provides registration service), Eureka Client (Java client, responsible for sending heartbeat)

Other microservices in the system use the Eureka client to connect to the Eureka server to maintain a heartbeat connection (that is, registration). Other modules of the Springcloud can be used by Eureka Server to discover and invoke microservices in the system

3, Eureka three major roles

Eureka Server: Providing service registration and discovery

Service Provider: A provider that registers its services with Eureka so that service consumers can find

Service Consumer: The consumer of services, from Eureka to obtain a list of registered services, so as to be able to consume services.

Second, Eureka Server Service Registration Center 1, Pom.xml
<!--Register a service center jar with multiple-server -<Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-starter-eureka-server</Artifactid>  </Dependency>
2, Application.yml
 Server: port:7001 Eureka: instance: hostname: localhost client:#declare yourself to be a service-side    Registerwitheureka: false#False indicates that you do not register yourself with the registry    Fetchregistry: false#false means that you are the registry, the responsibility is to maintain the instance, do not participate in the search    serviceurl:#set the interactive address of the Eureka server, which is the externally exposed address      Defaultzone: http://${eureka.instance.hostname}:${server.port}/eureka/

3. Startup class

// Note: To add @enableeurekaserver annotations before the class @SpringBootApplication@EnableEurekaServer   Public class Eureka7001_app {    publicstaticvoid  main (string[] args) {        Springapplication.run (Eureka7001_app. class , args);}    }

Run results

third, service provider services provider

Suppose this commodity microservices.

1, Pom.xml
        <dependency >            < groupId >org.springframework.cloud</groupId>            < Artifactid >spring-cloud-starter-netflix-eureka-client</artifactid>        </dependency>
  2, Application.yml
server:  port8001# Specify registry address  Eureka:  Client :    serviceurl:      defaultzone: http://localhost:7001/eureka/# name of the service  Spring:  application:    name: Product-service
3. Startup class
@SpringBootApplication  Public class productapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (productapplication. class , args);}    }
4. Check the service registration center after startup

Discover that a service has been registered in the service registry

5. Change the port number and start a 6, looking at the service center

This is the building of commodity microservices cluster.

iv. service consumer consumer

In fact, the service side and consumption in the configuration time without any difference, they belong to the Eureka client component. Only involves calls between services, so the callee is called the provider, and the caller is called the consumer. Like the Order Micro Service,

The order service definitely needs to adjust the commodity micro service, so this order micro service can understand the service provider for the commodity. A microservices can be both a service side and a provider.

1, Pom.xml
    <!--this is added to each microservices that are not registered as a hub -        <Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-starter-netflix-eureka-client</Artifactid>        </Dependency>
2, Application.yml
server:  Port9001# Specify registry address  Eureka:  Client :    serviceurl:      defaultzone: http://localhost:7001/eureka/#  Name of the service  Spring:  application:    name: Order-service
3. Startup class
@SpringBootApplication  Public class orderapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (orderapplication. class , args);}    }
4. Check the registration center

Discovery Order Micro Service also successfully registered to the registration center

As for the order micro Service How to adjust the commodity microservices, the next time the blog is written.

I just occasionally calm down and ponder over all the past. It's not worth condemning those old times that have been naïve and dull. After all, the days ahead are still long. Keep encouraging yourself,

The day is bright, is a new beginning, but also the Unknown Journey (Colonel 5)

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.