Service registry Eureka

------------ ------------ restore content begins

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
second)
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.
 
Introducing dependent parent project pom.xml defined SpringCloud version
<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>
Server   
 
Introduced eurek
<dependencies> 
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring‐cloud‐starter‐netflix‐eureka‐ server</artifactId>
</dependency>
</dependencies>

 

appliction.yml

Server: 
  Port: 6868 # service port 
Eureka: 
  Client: 
    registerWithEureka:
false # whether to register their services to Eureka itself is not required to register all     fetchRegistry: false # whether to obtain registration information from Eureka in     serviceUrl: #Eureka client and Eureka Service address terminal interacting       defaultzone: HTTP: // 127.0.0.1:${server.port}/eureka/
Server:
eviction-interval the MS-Timer-in-: 0 // set the time to clear an invalid node interval (unit: ms )

 Start class @EnableEurekaServer

@SpringBootApplication 
@EnableEurekaServer
public class EurekaServer {

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

 

Client 

   The introduction of dependence

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

application.yml arrangement 

eureka: 
    client:
         service‐url: defaultZone: http://localhost:6868/eureka   
          registry-fetch-interval-seconds: 30 // pull service registration information of the time the default 30 seconds
 instance: 
eureka.instance.instance-ID: // example XXX ID the prefer-IP-address:
to true // display IP
Lease-Renewal-in-seconds The interval The-: // 30 does not receive the heartbeat after the default 30 30s, will be removed examples of change.
  lease-expiration-duration-in- seconds: 90 // 90 default setting expiration excluding time (in seconds) eureka server represents the first time after the receipt of client heartbeat timeout waiting for the next heartbeat.

                                                           If the value is too large, it is likely to flow forward in the past when the instance has not survived.

                                                           If the value is set too small, the instance is likely due to temporary network jitter is removed away.

                                                            This value should be at least greater than leaseRenewalIntervalInSeconds.

Startup class 
@EnableEurekaClient

 

 

 

protection mechanism 

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).
 
When stand-alone test 
 eureka.server.enable-self-preservation = false closing protection mechanism 

 

 

Guess you like

Origin www.cnblogs.com/qin1993/p/12566168.html