This is my 21st day of the August Genwen Challenge

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

As we mentioned in the previous section, every instance registered to Eureka is an instance of Eureka. Whether the instance itself is Eureka Server or a microservice to be registered, as long as the instance is used, the instance configuration is required. Instance configuration in our series, especially Eureka instance configuration in Spring Cloud (based on Spring-Cloud-Netflix), starts with Eureka. The corresponding configuration class is EurekaInstanceConfigBean

Instance configuration will affect the instance information, heartbeat time, expiration time and other information on Eureka Server. Meanwhile, some micro-service frameworks will use metadata in instances to implement load balancing and disconnection policies.

Instance configurations all start with Eureka. Instance and the corresponding class is EurekaInstanceConfigBean

The first is the information needed to access the Eureka instance, which is usually read automatically without our own manual configuration:

The constructor of the eureka: instance: eureka: instance: eureka: instance: The EurekaInstanceConfigBean constructor will fetch hostname from InetUtils.Copy the code

As for registries, you can configure whether you prefer to register directly with IP or domain names. Sometimes the IP address of the domain name mapping may change, but the address of the service itself remains the same. This is especially common in the cloud environment, so we generally configure IP registration:

Eureka: instance: # Prefer-ip-address: true prefer-ip-address: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: true prefer-ip: trueCopy the code

Generally, the port of the microservice is directly registered. This can also be configured, because some SideCar applications may register different ports from their own Spring Boot service ports.

Eureka: instance: # use server. Port as non-secure-port # if secure-port-enabled is true, server.port is automatically used as secure-port; Secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port: non-secure-port Secure-port is not enabled by default. We usually do not use SSL secure-port-enabled for internal calls: falseCopy the code

At the same time, we can also customize the name of the registered micro-service and the ID of the instance:

Eureka: instance: # personalize instance id, including IP: microservice name: port instance-id: ${spring.cloud.client.ip-address}:${spring.application. Name}:${server.port} # app name, Spring.application. Name AppName: ${spring.application. Name} # app-group-name: common # namespace: publicCopy the code

This information is not useful for Eureka itself. It is mainly used for external monitoring, such as obtaining instance information from Eureka and checking instance health based on basic link information.

IP address of the actuator in the zone using the same IP address as that in the zone using the same IP address as that in the zone using the same IP address as that in the zone using the same IP address as that in the zone using the same IP address /actuator/health # indicates the IP address of the device. The default is /actuator/info status-page-url-path: /actuator/info # indicates the IP address of the device. The default is /home/page-url-path: /Copy the code

Instance registration behavior configuration, that is, the behavior of the instance after registration, and heartbeat interval configuration. The Eureka client will heartbeat based on this configuration and whether to register itself as UP to start the service at the beginning, or register itself as STARTING and then change to UP after some initialization task is completed. The Eureka Server also determines whether an instance is alive based on this configuration and the last heartbeat time of the instance

eureka: instance: EurekaServer will reject this instance if no heartbeat is received after this time. EurekaServer must be set eurekag.server. Eviction -interval-timer-in-ms, any configuration will be invalid. The configuration is designed to be three times the configured service refresh time Lease -expiration-duration-in-seconds: 15 # Configure the service refresh time, at which the active heartbeat will be performed once. The default value is false. The default value is "STARTING". After the status changes, it will be changed to UP instance-enabled-onit: falseCopy the code

Other frameworks can use instance metadata to implement personalized functions, such as configPath, which is set when spring-cloud-config is used, and zone, which is the instance configuration, which is used by spring-cloud-loadbalancer.

Eureka: instance: # metadata map, we can use it ourselves, put some personalized metadata, currently only configPath and zone are useful. Metadata-map: # Spring Cloud configPath: metadata-map: # Spring Cloud configPath: Metadata-map: # Spring Cloud configPathCopy the code

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

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