Had been introduced

1. Registry Overview

What is a registry?

The client is provided with a list of services that can be invoked. When making a remote call (RPC), the client selects the service address of the service provider from the list to invoke the service

The core functions of the registry

  • Registration: The service provider reports the description of the service
  • Discover: The consumer obtains the corresponding service description based on the service name
  • Service health check/probe mechanism: The main purpose is to update the list of services in the registry

There are several common registries in the industry

Zookeeper(Java), ETCD (Go), Consul(Go), Eureka(Java), Nacos(Java)

2. Basic concepts of Eureka

Eureka is a service discovery framework developed by Netflix. As a REST-based service, Eureka is mainly used to locate middle-tier Services running in AWS(Amazon Web Services, Amazon Cloud) domain, so as to achieve load balancing and middle-tier service failover. SpringCloud integrates it into its sub-project spring-Cloud-Netflix to realize SpringCloud’s service discovery capabilities. In essence, Eureka is a dedicated server for service discovery, where some services register and other services find the services they want to invoke and execute. There are many components that can serve as a service discovery server, such as Zookeeper and Consul.

Eureka architecture

3 CAP theorem
  • concept

    CAP theorem refers to the principle that Consistency, Availability and Partition tolerance are incompatible in a distributed system.

    • Consistency (C): Indicates whether data consistency can be maintained among multiple hosts in a distributed system. That is, after system data is updated, data on all hosts remains in the same state.

    • Availability (A): The services provided by the system must always be available, that is, for each request of the user, the system can always respond to the user within A limited time.

    • Partition fault tolerance (P): the distributed system can still ensure that the external supply meets the requirements of one when encountering any network partition failure

      Compliance and availability of services.

  • theorem

    The content of CAP theorem is: for distributed system, network environment is relatively uncontrollable, network partition is inevitable, so the system must have fault tolerance of partition. But the system cannot guarantee consistency and availability at the same time. So either CP or AP.

4. Eureka lives in different places

The concepts of Region and Avaliablity Zone in Eureaka are the concepts of cloud computing. In order to facilitate the use of users in different geographical regions, large cloud service providers will generally create different large cloud computer rooms in different cities, provinces, countries or continents according to the user demand. The rooms in these regions cannot be connected to the Intranet. These regions are called regions

How can same-region Dr Be implemented in the same Region room? The disaster recovery capability is enhanced and different Avaliablity zones are configured in one Region. Intranet connectivity is achieved between these AZs and users can automatically select different AZs in the same Region according to their specific location. When the AZ to be accessed by users has problems, the system will automatically switch to other available AZs

Eureka is easy to use

Eureka is divided into client and server. The following describes the simple use and configuration of Sever and client respectively

eureka-server
  1. Join the rely on

         <dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    Copy the code
  2. Mark EurekaServer

    @EnableEurekaServer // EureakaServer
    @SpringBootApplication
    public class EurekaServer01Application {
        public static void main(String[] args) { SpringApplication.run(EurekaServer01Application.class, args); }}Copy the code
  3. Simple configuration

    eureka:
      instance:
        Eureka host localhost specifies the host
        hostname: localhost
      client:
        # Register with Eurka Server indicates whether you need to register yourself
        register-with-eureka: true
        service-url:
          The address of the EurekaSever registry can be set to other machines in the cluster by defaulZone. If there are multiple machines in the cluster, separate them with commas (,)
          defaultZone: http://localhost:18081/eureka/
    Copy the code
  4. Launch access http://localhost:18081

eureka-client
  1. Join the rely on

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    Copy the code
  2. Simple configuration

    eureka:
      instance:
        hostname: localhost
      client:
        service-url:
          defaultZone: http://localhost:18081/eureka/
    Copy the code
  3. Launch access http://localhost:18081