This is my 23rd day of the August Genwen Challenge

This series code address: github.com/HashZhang/s…

Eureka client configuration refers to the client configuration for accessing the Eureka Server, including the configuration of the Eureka Server address, the configuration of the pull service instance information, the configuration of the current instance registration, and the configuration of the HTTP connection. In Spring Cloud, the Eureka client configuration starts with Eureka. client, and the corresponding configuration class is EurekaClientConfigBean

Among them, Eureka client has three important scheduled tasks, as well as the related configuration, here is shown in the way of figure:

Read the process related to the service instance:

Periodically check instance information and instance status and synchronize to Eureka Server:

Timing heartbeat process:

The address of the Eureka Server can be specified directly, and these configurations can be changed dynamically and the refresh time can be configured. Such as:

eureka: client: service-url: EurekaClientConfigBean defaultZone = EurekaClientConfigBean (); http://127.0.0.1:8211/eureka/ zone1: http://127.0.0.1:8212/eureka/ zone2: http://127.0.0.1:8213/eureka/ zone3: http://127.0.0.1:8214/eureka/ # if eureka server address configuration updates related to the above, how long will read again after perceived eureka - service - url - poll interval - seconds: 300Copy the code

You can also obtain the Eureka Server through DNS. For example:

Eureka: client: # whether to use the DNS, if specified by the following DNS configuration available, rather than the above service - use url - DNS - for - fetching - service - urls: # eureka server port # eureka server port # eureka server port # eureka server port Context # eureka-server-u-r-l-context: /eurekaCopy the code

In addition, different Eureka servers may be deployed in different availability zones. You can also configure the zone configuration of the Eureka Client.

Eureka: client: # List of available zones. Key is region and value is zone availability- Zones: region1: Zone1, zone2 region2: Zone3 # fetch zone from availability-zones And then reading service - from the zone url to obtain the corresponding eureka url # corresponding class is the logic ConfigClusterResolver and ZoneAffinityClusterResolver region: Region1 # If set to true, eureka in the same zone will run first. Default: true prefer-same-zone-eureka: trueCopy the code

We can configure whether to pull the service instance information from Eureka or not. Generally, when we do not want to use the registered instance information on Eureka, we can disable the Eureka Client to obtain the micro-service instance information from Eureka by this configuration.

Eureka: Client: # Whether to fetch an instance from eureka fetch-registry: trueCopy the code

A request to pull service instance information can also be configured to pull compressed or complete information, and whether to get instance information by incremental pull. The implementation of Eureka incremental pull mechanism is very simple, that is, newly registered or eliminated instances will be put into the recently modified queue, and the information in the queue will be returned as the response to the incremental pull. Incremental pull may lose updates to some instances, but it saves network traffic and can be used when the network is bad. There is version control in the incremental pull, if the version is different, the full pull is still done, and then the incremental pull is done.

Eureka: Client: # Whether to disable incremental pull. If network conditions are not good, you can disable incremental pull. There is version control in the incremental pull, if the version is different, the full pull is still done, and then the incremental pull is done. The client request header specifies whether the instance information returned by the server is compressed or complete. The default is complete. Log -delta-diff: trueCopy the code

The pulled instance is saved to the local cache, which has an expiration time:

Eureka: client: # Eureka client refresh local cache time # default 30s registry-fetch-interval-seconds # filter-only- UP instances = true filter-only- UP instances True # Eureka client refreshes the thread pool size of the local cache. Default value: 2 cache-refresh-executor-thread-pool size: 2 # Maximum delay time for eureka client to refresh the local cache (timed fetch eureka instance list) thread pool task. This configuration is a multiple of registry-fetch-interval-seconds. The default value is 10 times cache-refresh-executor- exponent-back-off-boundCopy the code

Meanwhile, in the Spring Cloud environment, as long as it is a spring-Cloud-Commons based microservice implementation (in fact, all Spring Cloud implementations are based on this implementation), the Client of service discovery: DiscoveryClient (synchronous environment) and ReactiveDiscoveryClient (asynchronous environment) are both Composite implementations that use multiple internal service discovery clients. Service discovery invokes each Eureka Client in a certain order. You can also configure the order of Eureka clients.

eureka: client: DiscoveryClient is a CompositeDiscoveryClient in the Spring Cloud environment. The CompositeDiscoveryClient logic is composed of multiple DiscoveryClients, which are accessed first and then searched for the next one. The order determines the order, which defaults to 0 order: 0Copy the code

When we test locally, we may not want to register the local instance with the Eureka Server. This can also be configured:

Register-with-eureka: trueCopy the code

Meanwhile, Eureka instance information and configuration can be changed in the design of Eureka. How long will it be synchronized to Eureka Server? Note that unlike heartbeat requests, this can be configured separately:

Eureka: Client: # Interval between instance information and scheduled synchronization to eureka Server. Every so long, check whether the instance information (i.e. eureka. Instance configuration information) has changed. If it has changed, it will be synchronized to eureka Server. Instance-info-replication-interval-seconds: 40 40 initial-instance-info-replication-interval-seconds: 40Copy the code

There are a few other configurations we might also use:

Set this parameter to false because the instance cannot provide services properly: shoulder-registration-at-init: The default value is true: should-unregister-on-shutdown True # Whether to limit traffic for instance status change updates. The default value is true on-demand-update-status-change: trueCopy the code

The Eureka Client obtains service instance information based on Http requests. You can perform the following configuration for the Http Client:

Eureka: client: # proxy-host: # proxy-port: # proxy-user-name: # proxy-password: Gzip is a gzip compressed g-zip-content for HTTP requests sent to Eureka Server. Eureka-server-connect-timeout-seconds eureka-server-connect-timeout-seconds eureka-server-read-timeout-seconds Eureka-connection-idle-timeout-seconds = 30 seconds eureka-connection-idle-timeout-seconds Eureka-server-total-connections: Eureka-server-totals-connections-per-host: 50 # TLS: enabled false # key-password: # key-store: # key-store-password: # key-store-type: # trust-store: # trust-store-password: # trust-store-type:Copy the code

This section examines Eureka’s client configuration in detail. In the next section, we’ll start analyzing the configuration of Eureka Server.

Wechat search “my programming meow” public account, a daily brush, easy to improve skills, won a variety of offers