Springboot2.x integration service registry SpringCloud of Eureka

First,  what is the service registry

        A service registry is service to achieve a core component of service management , similar to the role of a directory service , mainly used to store service information , such as provider url string routing information . SOA service registry is one of the most basic facilities architecture.

the role of the service registry

  1, the service registered

  2, service discovery

2.  Common registry which

  1, Dubbo registries Zookeeper

  2, Sringcloud registries Eureka

3. The  service registry to solve any problems

  1. Service management;
  2. Dependency Management services;

4.  What is the Eureka registry

Eureka is Netflix developed service discovery component itself is based on a REST service. Spring Cloud integrate it in their subprojects spring-cloud-netflix in order to achieve Spring Cloud services registered in the discovery, while also providing the ability to load balancing, failover, and so on.

5.  Eureka registry three roles

5.1 Eureka Server

  By the Register , the Get , Renew provide services such as registration and discovery interfaces.

5.2 Application Service (Service Provider)

    Service provider

 The self-service instances registered with the Eureka Server in

5.3 Application Client (Service Consumer)

    Caller to the service

 By Eureka Server to obtain the list of services, consumer services.

Second,  building service provider in Eureka registry

1. Create a project

 

2, modify pom.xml file

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.1.9.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.angei</groupId>
12     <artifactId>eurekaserver</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>eurekaserver</name>
15     <description>Demo project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19         <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
20     </properties>
21 
22     <dependencies>
23         <dependency>
24             <groupId>org.springframework.cloud</groupId>
25             <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
26         </dependency>
27 
28         <dependency>
29             <groupId>org.springframework.boot</groupId>
30             <artifactId>spring-boot-starter-test</artifactId>
31             <scope>test</scope>
32         </dependency>
33     </dependencies>
34 
35     <dependencyManagement>
36         <dependencies>
37             <dependency>
38                 <groupId>org.springframework.cloud</groupId>
39                 <artifactId>spring-cloud-dependencies</artifactId>
40                 <version>${spring-cloud.version}</version>
41                 <type>pom</type>
42                 <scope>import</scope>
43             </dependency>
44         </dependencies>
45     </dependencyManagement>
46 
47     <build>
48         <plugins>
49             <plugin>
50                 <groupId>org.springframework.boot</groupId>
51                 <artifactId>spring-boot-maven-plugin</artifactId>
52             </plugin>
53         </plugins>
54     </build>
55 
56 </project>

Tip: If you load pom.xml IDEA has failed to download, you can add the following configuration in pom.xml, making it the country from Ali cloud images download content, the download speed will be increased dramatically.

<repositories>
    <repository>
        <id>aliyun</id>    
        <name>aliyun</name>    
        <url>https://maven.aliyun.com/repository/public</url>    
    </repository>    
</repositories>

3, modify application.properties global configuration file

 1 server:
 2   port: 8761
 3 eureka:
 4   instance:
 5     appname: provider-service
 6     hostname: localhost
 7   client:
 8     service-url:
 9       defaultZone:
10         http://localhost:8761/eureka/
11     register-with-eureka: false
12     fetch-registry: false

Description:

. 1  Server:
 2    Port: 8761
 . 3  Eureka:
 . 4    instance:
 . 5      # service name, default configuration values take spring.application.name, if none Unknown
 . 6      APPNAME: provider- -Service
 . 7      # sets the current instance of the host name
 . 8      hostname: localhost
 9    Client:
 10      Service- url: 
 11        # designated service center address registration, type HashMap, and provided with a set of defaults,
 12        # as the default Key defaultZone; default value to http: // localhost: 8761 / eureka , 
13        # If the service registry for the high-availability cluster, multiple registries addresses separated by commas.
14        defaultzone:
 15          HTTP: //localhost: 8761 / Eureka / 
16  
17      # whether to register itself to Eureka-Server, the default is to true
 18      the Register-with-Eureka: false 
19  
20     # whether the red Eureka-Server obtains service registration information, defaults to true
 21      FETCH -registry: false

Attachment: the Spring Cloud common configuration and the Eureka Description

4, modify the startup class

 1 import org.springframework.boot.SpringApplication;
 2 import org.springframework.boot.autoconfigure.SpringBootApplication;
 3 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 4 
 5 @SpringBootApplication
 6 @EnableEurekaServer
 7 public class EurekaserverApplication {
 8 
 9     public static void main(String[] args) {
10         SpringApplication.run(EurekaserverApplication.class, args);
11     }
12 
13 }

5, access Eureka-Server service management platform through a browser

 

Guess you like

Origin www.cnblogs.com/tubeWang/p/11628827.html