SpringCloud entry 2 --- Eureka (service discovery component)

SpringCloud Getting Started 1 Introduction ---

SpringCloud entry 2 --- Eureka (service discovery component)

SpringCloud Getting Started 3 --- Feign (service call component)

SpringCloud entry 4 --- Hystrix (fuse assembly)

SpringCloud entry-5 --- Zuul (Serving Gateway)

The second, we do the right SpringCloud in Eureka (service discovery component) a brief description:

1, Eureka Introduction

       Eureka is a service discovery framework developed by Netflix, SpringCloud to integrate it in their own subprojects spring-cloud-netflix, the realization SpringCloud service discovery. Eureka consists of two components: Eureka Server and Eureka Client. Eureka Server service registration services, after each node starts, it will be registered in Eureka Server, so EurekaServer in the service registry will store all information available information service node, service node can visually see in the interface . Java Eureka Client is a client for interacting with the simplified Eureka Server, the client will do the same time a built-in polling (round-robin) load load balancing algorithm. After the application starts, will be sent to Eureka Server heartbeat, the default period is 30 seconds, if Eureka Server does not receive a node in a multiple heartbeat heartbeat period, Eureka Server service from the registry will put the service node remove (default 90 seconds).         

       Between Eureka Server synchronization is accomplished by way of copying data, Eureka also provides client-side caching mechanism, even if all of Eureka Server will hang up, the client still can use the information in the cache API consumption of other services. In summary, Eureka heartbeat checking, client caching mechanisms to ensure high system availability, flexibility and scalability.

2, Eureka server development

(1) Create a eureka module
(2) the introduction of the definition of dependent parent project pom.xml version SpringCloud

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring‐cloud‐dependencies</artifactId>
            <version>Finchley.M9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

  (3) eureka eureka-server module incorporated pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring‐cloud‐starter‐netflix‐eureka‐server</artifactId>
    </dependency>
</dependencies>

 (4) Addition application.yml

server:
  port: 8761 #服务端口
eureka:
  client:
    registerWithEureka: false #是否将自己注册到Eureka服务中,本身就是所有无需注册
    fetchRegistry: false #是否从Eureka中获取注册信息
    serviceUrl: #Eureka客户端与Eureka服务端进行交互的地址
      defaultZone: http://127.0.0.1:${server.port}/eureka/

  (5) to start writing class

    Create a package com.test.eureka, established under class package

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
   public static void main(String[] args) {
       SpringApplication.run(EurekaServer.class, args);
    }
}

 (6) up and running startup class, and then enter in the browser address bar http: // localhost: 8761 /, accessible interface

 

The main interface of system status information system for the general information General Info Instances currentlyregistered with Eureka registered to the list of all the micro-services.

3, Eureka client registration

    We will now all services are registered with the micro Eureka, so between all of the micro-services can call each other.

 (1) add other micro-dependent service module

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring‐cloud‐starter‐netflix‐eureka‐client</artifactId>
</dependency>

 (2) modify each micro services application.yml, add the configuration register eureka services

eureka:
  client:
    service‐url:
      defaultZone: http://localhost:6868/eureka
  instance:
    prefer‐ip‐address: true

  (3) modify each service class start classes, add annotations

@EnableEurekaClient

  (4) Start test: each micro service starts up, you will find a list of registered eureka can be seen in these micro-served

4, eureka protected mode

 If you see the following tips in this Eureka Server home page, then Eureka has entered the protection mode:

Eureka Server During operation, the statistics of heart failure in the ratio is lower than 85% within 15 minutes, if the situation appears less than (it is easy to meet when stand-alone debugging on actual production environment is usually due to network instability lead), Eureka Server instance of the current registration information will be protected, and this prompted the warning. Protected mode is mainly used in the presence of a protective network partition between a scene and a set of client Eureka Server. Once in protected mode, Eureka Server will try to protect its information service registry, delete data no longer service registry (which is not written off any micro-services). 

So far, eureka related to the completion of already introduced, Dubbo understanding of children's shoes can be seen is the role of Zookeeper, service registry, children's shoes are recommended to use a lift.

 

Published 41 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/u014526891/article/details/87391419