Eureka is Netflix’s open source REST-based service governance solution. It is divided into Server and Client. The Server is the registry, and other micro services are registered and discovered through the Client. Sc-parent, parent module SC-provider, provider module SC-Eureka, registry sc-consumer-Discovery, consumer module building parent module creating parent module SC-parent, POM.xml: The < project XMLNS = “http://maven.apache.org/POM/4.0.0” XMLNS: xsi = “http://www.w3.org/2001/XMLSchema-instance” Xsi: schemaLocation = “http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd” > The < modelVersion > 4.0.0 < / modelVersion > < groupId > com. Cf < / groupId > < artifactId > sc – parent < / artifactId > < version > 0.0.1 – the SNAPSHOT < / version > < packaging > pom < / packaging >
org.springframework. Boot

spring-boot-starter-parent


2.1.6.RELEASE

3.1.1


org.springframework.boot


spring-boot-starter-web




< the dependency > < groupId > org. Springframework. Cloud < / groupId >

spring-cloud-dependencies


Greenwich.SR2


pom


import




Spring-boot-maven-plugin

org.apache.maven.plugins < artifactId > maven — the compiler plugin < / artifactId > < configuration > < source > 1.8 < / source > < target > 1.8 < / target > Build the registry 1. Create submodule project sc-eureka, POM.xml under parent module: The < project XMLNS = “http://maven.apache.org/POM/4.0.0” XMLNS: xsi = “http://www.w3.org/2001/XMLSchema-instance” Xsi: schemaLocation = “http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd” > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > com. Cf < / groupId > < artifactId > sc – parent < / artifactId >

0.0.1-SNAPSHOT


sc-eureka


< the dependency > < groupId > org. Springframework. Cloud < / groupId >

spring-cloud-starter-netflix-eureka-server

2. EurekaApplication: package eureka; import org.springframework.boot.SpringApplication; importorg.springframework.boot.autoconfigure.SpringBootApplication; importorg.springframework.cloud.netflix.eureka.server.EnableEurekaServer; // Declare the microservice to be a registry, Provide the function of the service discovery and registration @ EnableEurekaServerpublicclass EurekaApplication {public static void main (String [] args) { SpringApplication.run(EurekaApplication.class, args); }} 3. Create a configuration file/SRC/main/resources/application. The yml: server: port: 8080 # current service port eureka: instance: Hostname :localhost # registerWithEureka False # indicates that this client does not need to obtain the Eureka registry information serviceUrl from the Eureka registry: DefaultZone: http://localhost:8080/eureka/ # # had been providing address (address of client connection) For other configuration information, refer to the EurekaInstanceConfigBean and EurekaClientConfigBean. Run the startup class EurekaApplication and visit http://localhost:8080/ in the browser. If the following picture appears, the registry is successfully set up:

1. Create a submodule project sc-provider, POM.xml under the parent module: The < project XMLNS = “http://maven.apache.org/POM/4.0.0” XMLNS: xsi = “http://www.w3.org/2001/XMLSchema-instance” Xsi: schemaLocation = “http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd” > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > com. Cf < / groupId > < artifactId > sc – parent < / artifactId >

0.0.1-SNAPSHOT


sc-provider


< the dependency > < groupId > org. Springframework. Cloud < / groupId >

spring-cloud-starter-netflix-eureka-client

2. Create start class provider. ProviderApplication: package provider; importorg.springframework.boot.SpringApplication; importorg.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplicationpublic class ProviderApplication { public static void main(String[] args) { SpringApplication.run(ProviderApplication.class, args); }} 3. Create a Controller: the provider) Controller. BookControllerpackage provider. The Controller; importorg.springframework.web.bind.annotation.GetMapping; importorg.springframework.web.bind.annotation.RequestMapping; importorg.springframework.web.bind.annotation.RestController; @RequestMapping(“/book”)@RestControllerpublic class BookController { @GetMapping(“/list”) public String getBookList(){ Return “[“Java start to quit “,”C++ start to quit “,”Python start to quit “,”C start to quit “]”; }} 4. Create a configuration file/SRC/main/resources/application. The yml: server: port: 8081 spring: application: name: Sc-provider # register the service name in the Eureka registry. Eureka: Client: serviceUrl: defaultZone: http://localhost:8080/eureka/ # registry access address instance: preferIpAddress: true # says it will register their IP to Eureka registry. 5. Start the registry SC-Eureka and provider SC-Provider in sequence. When the provider is started, it registers its information with the Eureka registry. Visit http://localhost:8080/ in your browser, and the provider sc-Provider is registered with the registry.

1. Create submodule project sc-consumer-discovery, POM.xml under parent module: The < project XMLNS = “http://maven.apache.org/POM/4.0.0” XMLNS: xsi = “http://www.w3.org/2001/XMLSchema-instance” Xsi: schemaLocation = “http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd” > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > com. Cf < / groupId > < artifactId > sc – parent < / artifactId >

0.0.1-SNAPSHOT


sc-consumer-discovery




org.springframework.cloud


spring-cloud-starter-netflix-eureka-client


2. Create start class consumer. ConsumerDiscoveryApplication: package consumer; importorg.springframework.boot.SpringApplication; importorg.springframework.boot.autoconfigure.SpringBootApplication; importorg.springframework.context.annotation.Bean; importorg.springframework.web.client.RestTemplate; @SpringBootApplicationpublic class ConsumerDiscoveryApplication { public static void main(String[] args) { SpringApplication.run(ConsumerDiscoveryApplication.class, args); } @Bean public RestTemplate restTemplate(){ return new RestTemplate(); }} 3. Create call provider service Controller: consumer. Controller. ConsumerDiscoveryControllerpackage consumer. The Controller; importjava.util.List; import org.springframework.beans.factory.annotation.Autowired; importorg.springframework.cloud.client.ServiceInstance; importorg.springframework.cloud.client.discovery.DiscoveryClient; importorg.springframework.web.bind.annotation.GetMapping; importorg.springframework.web.bind.annotation.RestController; importorg.springframework.web.client.RestTemplate; @RestControllerpublic class ConsumerDiscoveryController { @Autowired private DiscoveryClient discoveryClient; @Autowired private RestTemplate restTemplate; @getMapping (“/getBookList”) public String getBookList(){// Obtain instance information by service name. List

List = discoveryClient.getInstances(“sc-provider”); if (list ! = null && list.size() > 0) {// Call the service, And return service results returnrestTemplate. GetForObject (list. Get (0). GetUri () + “/ book/list”, String, class); } return null; Yml: server: port: 8082Spring: application: name: sc-consumer-discovery eureka: client: RegisterWithEureka: false # The consumer does not provide a service in this instance, so there is no need to register with the registry. In a practical application, the consumer may also be the provider. serviceUrl: defaultZone: http://localhost:8080/eureka/5. Start the registry SC-Eureka, provider SC-Provider, and consumer SC-consumer-Discovery in sequence. When the consumer starts, the list of available services and their network address will be queried from the registry

Springcloud Learning Note 1: Eureka service registration and discovery number of reads 347

Springcloud can easily help us complete the micro-service architecture. It has several sub-projects. You can go to the official website for a brief introduction. Where, the ones under Component represent the existing sub-projects, and eureka recorded this time is one of them, spring-cloud-… Blog post: meepoGuan’s blog

Registration and discovery of Learning notes in SpringCloud 164 Eureka readings

Infrastructure Service Registry: a server provided by Eureka that provides service registration and discovery. Service provider: An application that provides services. Service Consumer: A consumer application obtains a list of services from a service registry, enabling… From: SIMBA1949’s blog SpringCloud Study Notes 2: Eureka reading number 5

Before springCloud, dubbo, which is a remote call (RPC), was learned