package org.springframework.cloud.netflix.eureka;
import com.netflix.appinfo.EurekaAccept;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.env.PropertyResolver;
import org.springframework.util.StringUtils;
@ConfigurationProperties("eureka.client")
public class EurekaClientConfigBean implements EurekaClientConfig {
public static final String PREFIX = "eureka.client";
public static final String DEFAULT_URL = "http://localhost:8761/eureka/";
public static final String DEFAULT_ZONE = "defaultZone";
private static final int MINUTES = 60;
@Autowired(
required = false
)
PropertyResolver propertyResolver;
//是否启用Eureka客户端,默认true
private boolean enabled = true;
@NestedConfigurationProperty
private EurekaTransportConfig transport = new CloudEurekaTransportConfig();
//从Eureka服务端获取注册信息得间隔时间,单位为秒
private int registryFetchIntervalSeconds = 30;
//更新实例信息的变化到Eureka服务端的间隔时间,单位为秒
private int instanceInfoReplicationIntervalSeconds = 30;
//初始化实例信息到Eureka服务端的间隔时间,单位为秒
private int initialInstanceInfoReplicationIntervalSeconds = 40;
//轮询Eureka服务端地址更改的间隔时间,单位为秒。当我们与Spring Cloud Config配合动态刷新Eureka的serviceURL地址时需要关注该参数
private int eurekaServiceUrlPollIntervalSeconds = 300;
private String proxyPort;
private String proxyHost;
private String proxyUserName;
private String proxyPassword;
//读取Eureka Server信息的超时时间,单位为秒
private int eurekaServerReadTimeoutSeconds = 8;
//连接Eureka Server的超时时间,单位为秒
private int eurekaServerConnectTimeoutSeconds = 5;
private String backupRegistryImpl;
//从Eureka客户端到所有Eureka服务端的连接总数
private int eurekaServerTotalConnections = 200;
//从Eureka客户端到每个Eureka服务端主机的连接总数
private int eurekaServerTotalConnectionsPerHost = 50;
private String eurekaServerURLContext;
private String eurekaServerPort;
private String eurekaServerDNSName;
private String region = "us-east-1";
//Eureka服务端连接的空闲关闭时间,单位为秒
private int eurekaConnectionIdleTimeoutSeconds = 30;
private String registryRefreshSingleVipAddress;
//心跳连接池的初始化线程数
private int heartbeatExecutorThreadPoolSize = 2;
//心跳超时重试延迟时间的最大乘数值
private int heartbeatExecutorExponentialBackOffBound = 10;
//缓存刷新线程池的初始化线程数
private int cacheRefreshExecutorThreadPoolSize = 2;
//缓存刷新重试延迟时间的最大乘数值
private int cacheRefreshExecutorExponentialBackOffBound = 10;
private Map<String, String> serviceUrl = new HashMap();
private boolean gZipContent;
//使用DNS来获取Eureka服务端的serviceUrl,默认false
private boolean useDnsForFetchingServiceUrls;
//是否要将自身的实例信息注册到Eureka服务端,默认true
private boolean registerWithEureka;
//是否偏好使用处于相同Zone的Eureka服务端,默认true
private boolean preferSameZoneEureka;
private boolean logDeltaDiff;
private boolean disableDelta;
private String fetchRemoteRegionsRegistry;
private Map<String, String> availabilityZones;
//获取实例时是否过滤,仅保留UP状态的实例,默认true
private boolean filterOnlyUpInstances;
//是否从Eureka服务端获取注册信息,默认true
private boolean fetchRegistry;
private String dollarReplacement;
private String escapeCharReplacement;
private boolean allowRedirects;
private boolean onDemandUpdateStatusChange;
private String encoderName;
private String decoderName;
private String clientDataAccept;
private boolean shouldUnregisterOnShutdown;
private boolean shouldEnforceRegistrationAtInit;
public EurekaClientConfigBean() {
this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
this.gZipContent = true;
this.useDnsForFetchingServiceUrls = false;
this.registerWithEureka = true;
this.preferSameZoneEureka = true;
this.availabilityZones = new HashMap();
this.filterOnlyUpInstances = true;
this.fetchRegistry = true;
this.dollarReplacement = "_-";
this.escapeCharReplacement = "__";
this.allowRedirects = false;
this.onDemandUpdateStatusChange = true;
this.clientDataAccept = EurekaAccept.full.name();
this.shouldUnregisterOnShutdown = true;
this.shouldEnforceRegistrationAtInit = false;
}
public boolean shouldGZipContent() {
return this.gZipContent;
}
public boolean shouldUseDnsForFetchingServiceUrls() {
return this.useDnsForFetchingServiceUrls;
}
public boolean shouldRegisterWithEureka() {
return this.registerWithEureka;
}
public boolean shouldPreferSameZoneEureka() {
return this.preferSameZoneEureka;
}
public boolean shouldLogDeltaDiff() {
return this.logDeltaDiff;
}
public boolean shouldDisableDelta() {
return this.disableDelta;
}
public boolean shouldUnregisterOnShutdown() {
return this.shouldUnregisterOnShutdown;
}
public boolean shouldEnforceRegistrationAtInit() {
return this.shouldEnforceRegistrationAtInit;
}
public String fetchRegistryForRemoteRegions() {
return this.fetchRemoteRegionsRegistry;
}
public String[] getAvailabilityZones(String region) {
String value = (String)this.availabilityZones.get(region);
if (value =&
Spring Cloud服务注册类配置参数注释
最新推荐文章于 2024-03-06 17:27:00 发布