摘要: 原创出处 http://www.iocoder.cn/Eureka/instance-registry-class-diagram/ 「芋道源码」欢迎转载,保留摘要,谢谢!
本文主要简介 注册表 InstanceRegistry 的类关系 ,为后文的 应用实例注册发现 、 Eureka-Server 集群复制 做整体的铺垫。
com.netflix.eureka.registry.AwsInstanceRegistry ,主要用于亚马逊 AWS,跳过。 com.netflix.eureka.registry.RemoteRegionRegistry ,笔者暂时不太理解它的用途。目前猜测 Eureka-Server 集群和集群之间的注册信息的交互方式。查阅官方资料, 《Add ability to retrieve instances from any remote region》 在做了简单介绍。翻看目前网络上的博客、书籍、项目实战,暂时都没提及此块。估摸和亚马逊 AWS 跨区域( region ) 机制有一定关系,先暂时跳过。有了解此块的同学,麻烦告知下笔者,万分感谢。TODO:疑问:RemoteRegionRegistry。 com.netflix.discovery.shared.LookupService ,查找服务 接口 ,提供 简单单一 的方式获取应用集合( com.netflix.discovery.shared.Applications ) 和 应用实例信息集合( com.netflix.appinfo.InstanceInfo )。接口代码如下:
public interface LookupService<T>{
Application getApplication(String appName);
Applications getApplications();
List<InstanceInfo> getInstancesById(String id);
InstanceInfo getNextServerFromEureka(String virtualHostname, boolean secure);
}
com.netflix.eureka.registry.InstanceRegistry 继承该接口。 com.netflix.eureka.lease.LeaseManager ,租约管理器 接口 ,提供租约的注册、续租、取消( 主动下线 )、过期( 过期下线 )。接口代码如下:
public interface LeaseManager<T>{
void register(T r, int leaseDuration, boolean isReplication);
boolean cancel(String appName, String id, boolean isReplication);
boolean renew(String appName, String id, boolean isReplication);
void evict();
}
com.netflix.eureka.registry.InstanceRegistry , 应用实例 注册表 接口 。它继承了 LookupService 、LeaseManager 接口,提供应用实例的 注册 与 发现 服务。另外,它结合实际业务场景,定义了 更加丰富 的接口方法。接口代码如下:
public interface InstanceRegistry extends LeaseManager<InstanceInfo>, LookupService<String>{
// ====== 开启与关闭相关 ======
void openForTraffic(ApplicationInfoManager applicationInfoManager, int count);
void shutdown();
void clearRegistry();
// ====== 应用实例状态变更相关 ======
void storeOverriddenStatusIfRequired(String appName, String id, InstanceStatus overriddenStatus);
boolean statusUpdate(String appName, String id, InstanceStatus newStatus,
String lastDirtyTimestamp, boolean isReplication);
boolean deleteStatusOverride(String appName, String id, InstanceStatus newStatus,
String lastDirtyTimestamp, boolean isReplication);
Map<String, InstanceStatus> overriddenInstanceStatusesSnapshot();
// ====== 响应缓存相关 ======
void initializedResponseCache();
ResponseCache getResponseCache();
// ====== 自我保护模式相关 ======
long getNumOfRenewsInLastMin();
int getNumOfRenewsPerMinThreshold();
int isBelowRenewThresold();
boolean isSelfPreservationModeEnabled();
public boolean isLeaseExpirationEnabled();
// ====== 调试/监控相关 ======
List<Pair<Long, String>> getLastNRegisteredInstances();
List<Pair<Long, String>> getLastNCanceledInstances();
}
com.netflix.eureka.registry.AbstractInstanceRegistry ,应用对象注册表 抽象实现 。
这里先不拓展开, 《Eureka 源码解析 —— 应用实例注册发现》系列 逐篇分享。
com.netflix.eureka.registry.PeerAwareInstanceRegistry ,PeerAware ( 暂时找不到合适的翻译 ) 应用对象注册表 接口 ,提供 Eureka-Server 集群内注册信息的 同步 服务。接口代码如下:
public interface PeerAwareInstanceRegistry extends InstanceRegistry{
void init(PeerEurekaNodes peerEurekaNodes) throws Exception;
int syncUp();
boolean shouldAllowAccess(boolean remoteRegionRequired);
void register(InstanceInfo info, boolean isReplication);
void statusUpdate(final String asgName, final ASGResource.ASGStatus newStatus, final boolean isReplication);
}
com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl ,PeerAware ( 暂时找不到合适的翻译 ) 应用对象注册表 实现类 。
这里先不拓展开, 《Eureka 源码解析 —— Eureka-Server 集群》系列 逐篇分享。
本文是一篇 简介 ( 啪啪啪,打脸 ),如果胖友比较着急想了解原理,可以阅读 携程 ——《深度剖析服务发现组件Netflix Eureka》 先,写的非常非常非常不错。
快马加鞭,更新 《Eureka 源码解析 —— 应用实例注册发现 (一)之注册》 ing ...
胖友,分享我的公众号( 芋道源码 ) 给你的胖友可好?