Eureka重要对象简介

2019-10-25 06:43:07来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

Eureka重要对象简介

在进行分析EurekaClient和EurekaServer之间通信的源码之前,我们首先需要熟悉一下几个实体类

InstanceInfo

这个类代表着EurekaClient实例,客户端向服务端请求注册时就会携带着这个实例,这个实例中包含了当前客户端的一些基本信息:

    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

这个枚举中包含了客户端可能存在的状态

        UP, 
        DOWN, 
        STARTING, 
        OUT_OF_SERVICE, 
        UNKNOWN;
Lease

这个类是服务端用来保存客户端的租约信息的,其中holder中持有的就是InstanceInfo对象

// 租约过期时间
 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();
}

本文由博客一文多发平台 OpenWrite 发布!


原文链接:https://www.cnblogs.com/zhixiang-org-cn/p/11710793.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Java生鲜电商平台-电商起送价的深入思考与实战

下一篇:Mybatis学习 三