1. 概述

本文主要简介 注册表 InstanceRegistry 的类关系,为后文的应用实例注册发现Eureka-Server 集群复制做整体的铺垫。

推荐 Spring Cloud 书籍

  • 请支持正版。下载盗版,等于主动编写低级 BUG 。

  • 程序猿DD —— 《Spring Cloud微服务实战》

  • 周立 —— 《Spring Cloud与Docker微服务架构实战》

  • 两书齐买,京东包邮。

推荐 Spring Cloud 视频

  • Java 微服务实践 - Spring Boot

  • Java 微服务实践 - Spring Cloud

  • Java 微服务实践 - Spring Boot / Spring Cloud

2. 类图

  • 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[0009]:RemoteRegionRegistry。

  • 蓝框部分,本文主角。

3. LookupService

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);

}

  • 在 Eureka-Client 里,EurekaClient 继承该接口。

  • 在 Eureka-Server 里,com.netflix.eureka.registry.InstanceRegistry 继承该接口。

4. LeaseManager

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();

}

5. InstanceRegistry

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();
}

6. AbstractInstanceRegistry

com.netflix.eureka.registry.AbstractInstanceRegistry,应用对象注册表抽象实现

这里先不拓展开,《Eureka 源码解析 —— 应用实例注册发现》系列 逐篇分享。

7. PeerAwareInstanceRegistry

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);
}

8. PeerAwareInstanceRegistryImpl

com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl,PeerAware ( 暂时找不到合适的翻译 ) 应用对象注册表实现类

这里先不拓展开,《Eureka 源码解析 —— Eureka-Server 集群》系列 逐篇分享。

666. 彩蛋


©著作权归作者所有:来自51CTO博客作者mb5ff80520dfa04的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 面试官:高并发下重启服务,接口调用老是超时,你有什么解决办法?
  2. 如何实时主动监控你的网站接口是否挂掉并及时报警
  3. kubernetes高可用集群安装(二进制安装、v1.20.2版)
  4. 使用Flask在服务器实现一个API接口。
  5. MySQL+Flask,在本地实现一个API接口。
  6. 手把手教你搭建一个 Elasticsearch 集群
  7. python 接口自动化测试-----常见面试题汇总
  8. 一款优秀的 SDK 接口设计十大原则
  9. C#基础入门第十三天(多态接口)

随机推荐

  1. php技术栈是什么
  2. php中的array_fill函数怎么用
  3. php怎么做页面静态化
  4. php中的array_combine函数怎么用
  5. php levenshtein函数怎么用
  6. php中的count_chars函数怎么用
  7. php中的array_search函数怎么用
  8. php中的str_word_count函数怎么用
  9. php中的array_slice函数怎么用
  10. php中的similar_text函数怎么用