Spring Cloud-based microservices build learning-3 Spring Cloud Eureka Configuration

Source: Internet
Author: User

Detailed configuration

In the service governance system of Eureka, it is mainly divided into service side and client. The server is the service registry, and the client is the micro-service application that provides the interface. When you deploy a highly available registry, each server is also a client, so in the process of using spring Cloud Eureka, we do almost everything we do with the configuration of the Eureka client, so we understand the configuration of this section, It's very helpful for using good eureka.
While the Eureka server is more like a ready-made product, in most cases, we don't need to modify its configuration information.

Eureka Client Configuration Classifications
    1. Service registration-related configuration, including the address of the service registry, the time interval for service acquisition, the availability zone, and so on.
    2. Service instance-related configuration, including the name of the service instance, IP address, port number, health check path, and so on.
Service Registration class Configuration

With regard to the configuration information of the service registration class, we can org.springframework.cloud.netflix.eureka.EurekaClientConfig obtain more detailed content than the official documents by viewing the source code. These configuration information is already eureka.client prefixed.

Specify a registration center

Specifies that the registry is eureka.client.serviceUrl implemented primarily through parameters.
If we build a highly available registry cluster, we can configure multiple registry addresses for the value values of the parameters. For example:

eureka.client.serviceurl.defaultzone=http://peer1:1111/eureka,http://peer2:1112/eureka/

In order to serve the security of the registry, many times we will join the security check for the service registry. At this time, when configuring serviceurl, you need to include the appropriate security check information in the value URL, such as:
http://<username>:<password>@localhost:1111/eureka

Other common configurations

These common configurations are already eureka.client prefixed

Name of parameter Description Default Value
Enabled Enable Eureka Client True
Registryfetchintervalseconds The interval of time to obtain registration information from the Eureka server, in seconds 30
Instanceinforeplicationintervalseconds Update the change in instance information to the Eureka server interval, in seconds 30
Initialinstanceinforeplicationintervalseconds The interval between the initialization of the instance information and the Eureka server, in seconds 40
Eurekaserviceurlpollintervalseconds The interval of time, in seconds, between polling for Eureka service-side address changes. When we integrate with Spring CLoud config, we need to pay attention to this parameter when dynamically refreshing Eureka's serviceurl address 300
Eurekaserverreadtimeoutseconds Time-out period for reading Eureka server information in seconds 8
Eurekaserverconnecttimeoutseconds Time-out period for link Eureka server in seconds 5
Eurekaservertotalconnections Total connections from Eureka client to all Eureka Server 200
Eurekaservertotalconnectionsperhost Total connections from Eureka clients to each Eureka server host 50
Eurekaconnectionidletimeoutseconds Eureka Idle shutdown time for server-side connections, in seconds 30
Heartbeatexecutorthreadpoolsize Number of initialization threads for the heartbeat connection pool 2
Heartbeatexecutorexponentialbackoffbound Maximum multiply value of the heartbeat timeout retry delay time 10
Cacherefreshexecutorthreadpoolsize Number of initialization threads for cache flush thread pool 2
Cacherefreshexecutorexponentialbackoffbound Maximum multiplication value for cache refresh retry delay time 10
Usednsforfetchingserviceurls Use DNS to get the serviceurl of the Eureka server False
Registerwitheureka Do you want to register your instance information with the Eureka server True
Prefersamezoneeureka Prefer to use the Eureka server in the same zone True
Filteronlyupinstances Whether to filter for instances, keep only instances of up state True
Fetchregistry Whether to obtain registration information from the Eureka server True
Service Instance class configuration

Regarding the service instance class configuration information, we can org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean obtain the detailed content through the view source code, these configuration information is eureka.instance prefixed.

Meta data

Metadata is an object that Eureka clients use to describe their service information when they want to send a registration request to a service registry, which contains standardized metadata such as service name, instance name, instance IP, instance port, and other important information for service governance , as well as some custom metadata information for load balancing policies or other special purposes.
We can eureka.instance.<properties>=<value> configure the normalized metadata directly in the format, which properties is EurekaInstanceConfigBean the name of the member variable in the object. For custom metadata, it can be eureka.instance.metadataMap.<key>=<value> configured in a format such as:

Eureka.instance.metadatamap.zone=shanghai

Instance Name configuration

InstanceInfo instanceId is the parameter in, which is the unique identity that distinguishes different instances in the same service. In the native implementation of the Netflix Eureka, the instance name takes the hostname as the default value, which causes the same
Multiple identical service instances cannot be started on the host. Therefore, in the spring Cloud Eureka configuration, the default naming of the instance name is extended more reasonably in the case of launching multiple instances in the unified host, which uses the following default rules:

${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}

For the naming conventions of instance names, we can also use eureka.instance.instanceId parameters to match them. Such as:

  eureka.instance.instanceId=${spring.application.name}:${random.int}

Using the above configuration, the application name plus the random number to distinguish between different instances, so that on the unified host, do not specify the port can easily start multiple instances of the effect.

Endpoint Configuration
    • Homepageurl: URL of the app home page
    • Statuspageurl: URL of Status page
    • Healthcheckurl: URL for Health Check
      Where the status page and health check URLs are used by default in spring Cloud Eureka the endpoints and endpoints provided by the Spring-boot-actuator module /info /health . And these endpoints play a very important role.

For the proper operation of the service, we must ensure that the endpoint of the Eureka client /health is an address that can be accessed by the registry when the metadata is sent, otherwise the service registry does not change state based on the health check of the app (only when the Healthcheck feature is turned on. Use this endpoint information as a health check). The /info endpoint, if not correct, causes the information interface provided by the service instance to be inaccessible when the instance of a single service is in the Eureka panel.
In most cases, we do not need to modify these URL configurations.

Health Testing

By default, the health detection of individual service instances in Spring CLoud Eureka is not achieved through the endpoints of the Spring-boot-actuator module /health , but relies on the client's heartbeat to keep the service instance alive. Therefore, the default heartbeat mode is not insured as a health check. It is not possible to detect whether a service is effectively serviced.
In spring Cloud Eureka, we can pass the Eureka client's health detection to the endpoint of the Spring-boot-actuator module with a simple configuration /health to achieve more comprehensive health state maintenance.
The detailed steps are as follows:

    1. Introduction of dependency of Spring-boot-starter-actuator module in Pom.xml
      xml
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
    2. application.propertiesadding parameter configurations ineureka.client.healthcheck.enabled=true
Other configurations

are eureka.instance prefixed by the following:

Name of parameter Description Default Value
Preferipaddress Whether the IP address is preferred as the host name identity False
Leaserenewalintervalinseconds Eureka the time interval at which the client sends a heartbeat to the server, in seconds 30
Leaseexpirationdurationinseconds Eureka the maximum amount of time the server waits after the last heartbeat is received, in seconds. After that time, the server rejects the service instance from the service manifest, thereby preventing the service invocation request from being sent to the instance 90
Nonsecureport Non-Secure communication port number 80
Secureport Secure Communication port number 443
Nonsecureportenabled Whether to enable non-secure communication port numbers True
Secureportenabled Whether to enable secure communication port numbers
AppName Service Name, default Spring.application.name configuration value, or unknown if not
Hostname Host name, when not configured, is based on the host name of the operating system to obtain

Reference documents
Spring Cloud micro-service combat

Spring Cloud-based microservices build learning-3 Spring Cloud Eureka Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.