Eureka service governance and configuration details

1, Eureka service governance mechanism

Eureka service governance has three elements: service provider, service consumer and registration center. The relationship between the three elements is as follows:

Service provider
Service registration

When the service provider starts, it will register the service with the registry through the REST request, and attach some metadata information of its own. Eureka Server will store these metadata information in a two-tier map structure (the first tier key is the service name -, and the second tier is the instance name - instance ID)

Renewal of service

The service provider will maintain a heartbeat to tell the registry that the instance is still alive, so that the registry will not reject it

Service Downline

When an instance of a service is shut DOWN or restarted normally, it will tell the registration center the offline status through the REST request. The registration center will remove the instance or change the status to DOWN. If the service exits abnormally, the registration center will wait until the service fails to remove it.

Service consumers
Service acquisition

The service consumer obtains a read-only service list from the registration center through the REST request, and updates the list once in 30 seconds by default

Service invocation

The service consumer obtains the specific instance name and metadata to be called according to the service name in the obtained service list. The metadata contains the calling address. The call of load balancing is realized through the Ribbon.

Registry Center
Failure elimination

If the service exits abnormally, the registry will not be informed of the REST request. When the registry starts, it has created a timer: regularly remove the overtime services from the service list.

Service synchronization

Since the registry is a cluster, once the service is registered in one of the registries, the registry will register the service with other registries in the broadcast mode to achieve service synchronization

Self protection

By default, if the registration center does not receive the renewal heartbeat of the service within a certain period of time, the service will be removed from the service list. However, the service and the registration center may not be able to communicate due to network reasons, and the service is healthy, so this removal operation is very dangerous. Therefore, if the registration center loses too many instances in a short period of time, it will enter self-protection Protect mode. During this period, the service in the service list will not be deleted until the communication is restored (the received heartbeat threshold reaches the set value)

2, Eureka Client building

Project structure


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
        <relativePath/> <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot</description>








        <!--Define common interface-->






    context-path: /serviceclient
  port: 9000
    name: serviceclient #Instance name
    #Register to the registry, default true
    register-with-eureka: true
    #Do you prefer to use service providers in the same zone
    prefer-same-zone-eureka: true
    #Can be understood as region
    region: guangzhou
    #Available room
      guangzhou: zone-1,zone-2
      #defaultZone: http://localhost:8080/eureka01/eureka/,http://localhost:8081/eureka02/eureka/
      zone-1: http://localhost:8080/eureka01/eureka/
      zone-2: http://localhost:8081/eureka02/eureka/
    instance-id: serviceclient01 #Hyperlink name under status
    #Display IP
    prefer-ip-address: true
    #Define the call interval of service task renewal
    lease-renewal-interval-in-seconds: 5
    #Define service expiration time
    lease-expiration-duration-in-seconds: 10
    #Metadata of instance information
      #Which computer room does the instance belong to
      zone: zone-1

Main startup class:

package com.example.serviceclient01;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//Open fuse
public class Serviceclient01Application {

    public static void main(String[] args) {, args);


3, Eureka configuration details

Service registration class configuration, EurekaClientConfigBean, prefix: eureka.client
Service URL: specify the registry, map structure, default zone = http: / / localhost: 8761 / Eureka, or configure security verification
enabled: enable client, default true
Registry fetch interval seconds: cache refresh interval for service manifest
instanceInfoReplicationIntervalSeconds: time interval from update instance to registry
initialInstanceInfoReplicationIntervalSeconds: time interval from initializing instance information to the registry
eurekaServiceUrlPollIntervalSeconds: polling the time interval of server address change. When integrating the config configuration center, parameters that need to be paid attention to when dynamically refreshing the eureka registered address
eurekaServerReadTimeoutSeconds: timeout for reading eureka server information
eurekaServerConnectTimeoutSeconds: timeout for connecting to eureka server
Eurekaservertoalconnections: total number of connections from eureka clients to all servers
Eurekaservertoalconnectionsperhost: total number of client connections to each server host
eurekaConnectionIdleTimeoutSeconds: idle shutdown time of server connection
Heartbeat executor thread poolsize: number of initialization threads of heartbeat connection pool
Heartbeat executorexponentialbackoffbound: the maximum multiple value of heartbeat timeout retry delay time
cacheRefreshExecutorThreadPoolSize: number of initialization threads in the cache refresh thread pool
cacheRefreshExecutorExponentialBackOffBound: the maximum multiplier value of cache refresh retry delay time
registerWithEureka: register to server or not, true by default
preferSameZoneEureka: do you prefer to use service providers in the same zone? Only pay attention when using region and zone
filterOnlyUpInstances: whether to filter when getting an instance. Only the instances in up state are retained
fetchRegistry: retrieval service
Service instance class configuration, EurekaInstanceConfigBean, prefix: eureka.instance
Use[start,end] to randomly specify the start port, and use{}{server.port} to specify the instance name
instanceId: the name of an instance, which distinguishes different instances in a unified service
Page of statusPageUrlPath: info
healthCheckUrlPath: health page
preferIpAddress: whether IP is preferred as the display of host name
leaseRenewalIntervalInSeconds: heartbeat interval
leaseExpirationDurationInSeconds: Service rejection time
Non secure port: non secure port, that is, http channel
securePort: secure port, https channel
Non secureportenable: enable or not
securePortEnable: enable or not


I'll give you another article about source code

Published 6 original articles, won praise 1, visited 7231
Private letter follow

Tags: Spring Maven REST Apache

Posted on Tue, 14 Jan 2020 03:00:17 -0500 by Pryach