• 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 发布!

  • 相关阅读:
    vim实用技巧
    《C程序设计语言》学习笔记
    《鸟哥的Linux私房菜:服务器搭建篇》第一部分学习笔记
    入职培训学习心得
    [NOI2013]树的计数
    bzoj1779 [Usaco2010 Hol]Cowwar 奶牛战争(网络流)
    P2944 [USACO09MAR]地震损失2Earthquake Damage 2(网络流)
    bzoj3218 a + b Problem(网络流+主席树)
    P4542 [ZJOI2011]营救皮卡丘(Floyd+网络流)
    P4843 清理雪道(上下界网络流)
  • 原文地址:https://www.cnblogs.com/zhixiang-org-cn/p/11710793.html
Copyright © 2020-2023  润新知