springcloud (b) Governance Registry Service

1 Overview

Core Services component of governance has three parts: service providers, service consumers registry.

In a distributed system architecture, each micro-services (service providers, service consumers) at startup, your information will be stored in the registry, we call this process is called service registration. Service consumers should call interface of the service provider, you have to find a service provider, network information registry query service providers from, and through this information to call interface of the service provider, this process is service discovery.

Since more than just a service call management service registration and service discovery, but also includes a management service that requires registration center for micro-documented service for unified management, and how to implement specific management? Each micro-services and registries done by heartbeat communication mechanism, each certain time interval micro services will once reported to the registry, the micro-service center for a long time, if not registered, it will automatically communicate with the destruction of a widget service. When a micro-network information service changes, re-registration. Meanwhile, the micro-side caching service can be saved through customer service addresses the need to call up and to ensure the timeliness of the services through the regular task of updating the way, this can reduce the pressure of the registry, the registry if a problem occurs, it will not affect calls between micro-services.

Service providers, service consumers, registry association:

  1. First, start the registry.
  2. When the service provider starts registration service can be provided at the registration center.
  3. When consumers start service in the registry subscription service need to call.
  4. Registration information center will be pushed to the service provider's service caller.
  5. Service caller invokes the service by the service provider information (IP, port, etc.).

Registration center core modules:

  • Service Registry: used to store information of each micro-services, the registry provides an API to query and manage the various micro-services.
  • Service Registration: Micro service when started, will own information stored in the registry.
  • Service Discovery: query network information services need to call the micro, such as IP address and port.
  • Service checks: Complete communicate with each heartbeat mechanism of micro-services complete the registration, if you find a widget service for a long time unable to access the service is destroyed.

Two, Spring Cloud Service Governance

Spring Cloud service management components can be used Consul and Eureka, where we choose to Eureka.

1. What is Eureka?
      Eureka is an open source Netflix REST-based service management solutions, Spring Cloud integrates Eureka,
namely Spring Cloud Eureka, service registration and service discovery functions, and can be set up based on Spring Boot micro-service applications easily complete integration out of the box achieve Spring Cloud service management functions.
 Spring Cloud of open source Netflix secondary packaging components, namely Spring Cloud Netflix, Spring Cloud Eureka is part of the Spring Cloud Netflix Micro suite of services, based Netflix Eureka achieve the second package, the actual development, we use Spring Cloud Eureka to complete service governance.

2, the composition of the Spring Cloud Eureka
       Spring Cloud Eureka mainly includes server and client components: Eureka Server server, Eureka Client client.

Eureka Server, a server-side service registration and discovery, also known service registry, Eureka supports highly available configurations.

Eureka Client is a client component, its function is to serve the micro Eureka Server to complete the registration and ongoing maintenance functions, including renewal, cancellation and so on. Require registration of micro service is connected by Eureka Client to complete the registration of Eureka Server, communicate with the micro registry services through the heartbeat mechanism, complete monitoring of the status of each service.

Simple to understand registry (Eureka Server) is equivalent to an electronic business platform, service providers (Eureka Client) is equivalent to the seller registers a shop on the platform, provided the sale of goods and services, consumer services (other Eureka Client) quite registered user accounts on the platform, then you can buy goods in each store in the platform, and the platform (Eureka Server) also provides buyers and sellers of information management functions, such as whether online sellers, which can provide specific services, etc. .

Third, the registration center set up

1. Create a parent maven project myspringcloud, pom introduced springboot dependence and springcloud dependence, as follows:

<!-- 引入 Spring Boot 的依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.7.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <!-- 引入 Spring Cloud 的依赖,管理 Spring Cloud 各组件 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2, create a sub-project under the parent module to achieve Eureka Server

3, registrycenter engineering pom add Eureka Server relies

   <!-- Eureka Server 依赖-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

4, create a profile application.yml under src / resource directory, add Eureka Server configuration.

server:
  port: 8761 #当前 Eureka Server 服务端口
eureka:
  client:
    register-with-eureka: false #是否将当前 Eureka Server 服务作为客户端进行注册。
    fetch-registry: false #是否获取其他 Eureka Server 服务的数据
    service-url:
      defaultZone: http://127.0.0.1:8761/eureka/ #注册中心的访问地址。
  instance:
    prefer-ip-address: true

5, create a startup class RegistryCenterApplication in java path

6, run RegistryCenterApplication class

7, access the registration center address  http://127.0.0.1:8761  see the following interface

So far, the registration center set up successfully.

 

 

Released seven original articles · won praise 0 · Views 174

Guess you like

Origin blog.csdn.net/m0_37874989/article/details/104426712