在進行分析EurekaClient和EurekaServer之間通訊的源碼以前,咱們首先須要熟悉一下幾個實體類app
InstanceInfo
這個類表明着EurekaClient實例,客戶端向服務端請求註冊時就會攜帶着這個實例,這個實例中包含了當前客戶端的一些基本信息:ide
private volatile String instanceId; private volatile String appName; @Auto private volatile String appGroupName; private volatile String ipAddr; private static final String SID_DEFAULT = "na"; @Deprecated private volatile String sid = SID_DEFAULT; private volatile int port = DEFAULT_PORT; private volatile int securePort = DEFAULT_SECURE_PORT; @Auto private volatile String homePageUrl; @Auto private volatile String statusPageUrl; @Auto private volatile String healthCheckUrl; @Auto private volatile String secureHealthCheckUrl; @Auto private volatile String vipAddress; @Auto private volatile String secureVipAddress; @XStreamOmitField private String statusPageRelativeUrl; @XStreamOmitField private String statusPageExplicitUrl; @XStreamOmitField private String healthCheckRelativeUrl; @XStreamOmitField private String healthCheckSecureExplicitUrl; @XStreamOmitField private String vipAddressUnresolved; @XStreamOmitField private String secureVipAddressUnresolved; @XStreamOmitField private String healthCheckExplicitUrl; @Deprecated private volatile int countryId = DEFAULT_COUNTRY_ID; // Defaults to US private volatile boolean isSecurePortEnabled = false; private volatile boolean isUnsecurePortEnabled = true; private volatile DataCenterInfo dataCenterInfo; private volatile String hostName; private volatile InstanceStatus status = InstanceStatus.UP; private volatile InstanceStatus overriddenStatus = InstanceStatus.UNKNOWN; @XStreamOmitField private volatile boolean isInstanceInfoDirty = false; private volatile LeaseInfo leaseInfo; @Auto private volatile Boolean isCoordinatingDiscoveryServer = Boolean.FALSE; @XStreamAlias("metadata") private volatile Map<String, String> metadata; @Auto private volatile Long lastUpdatedTimestamp; @Auto private volatile Long lastDirtyTimestamp; @Auto private volatile ActionType actionType; @Auto private volatile String asgName; private String version = VERSION_UNKNOWN;
InstanceStatus
這個枚舉中包含了客戶端可能存在的狀態spa
UP, DOWN, STARTING, OUT_OF_SERVICE, UNKNOWN;
Lease
這個類是服務端用來保存客戶端的租約信息的,其中holder中持有的就是InstanceInfo
對象code
// 租約過時時間 public static final int DEFAULT_DURATION_IN_SECS = 90; //客戶端實例 private T holder; //服務下線時間 private long evictionTimestamp; //註冊起始時間 private long registrationTimestamp; //取消註冊時間 private long serviceUpTimestamp; // 最後更新時間 private volatile long lastUpdateTimestamp; //租約持續時間 private long duration;
PeerEurekaNode
這個對象表明着集羣節點信息對象
/** * 服務地址 */ private final String serviceUrl; /** * Eureka-Server 配置 */ private final EurekaServerConfig config; /** * 批任務同步最大延遲 */ private final long maxProcessingDelayMs; /** * 應用實例註冊表 */ private final PeerAwareInstanceRegistry registry; /** * 目標 host */ private final String targetHost; /** * 集羣 EurekaHttpClient */ private final HttpReplicationClient replicationClient; /** * 批量任務分發器 */ private final TaskDispatcher<String, ReplicationTask> batchingDispatcher; /** * 單任務分發器 */ private final TaskDispatcher<String, ReplicationTask> nonBatchingDispatcher;
EurekaHttpClient
這個是Eureka客戶端與服務端通訊的接口接口
public interface EurekaHttpClient { EurekaHttpResponse<Void> register(InstanceInfo info); EurekaHttpResponse<Void> cancel(String appName, String id); EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus); EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info); EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info); EurekaHttpResponse<Applications> getApplications(String... regions); EurekaHttpResponse<Applications> getDelta(String... regions); EurekaHttpResponse<Applications> getVip(String vipAddress, String... regions); EurekaHttpResponse<Applications> getSecureVip(String secureVipAddress, String... regions); EurekaHttpResponse<Application> getApplication(String appName); EurekaHttpResponse<InstanceInfo> getInstance(String appName, String id); EurekaHttpResponse<InstanceInfo> getInstance(String id); void shutdown(); }