ServiceRegistry
SpringCloud 有一个类:ServiceRegistry,也就是服务注册中心的概念。
这是一个接口,需要各个注册中心去实现。
Nacos的实现类是NacosServiceRegistry,实现类 register、deregister、close、setStatus、getStatus等方法
心跳
nacos client 定期发送心跳给 nacos server
服务注册
client 访问 server 的 open api(http 接口)http://xx.xx.xx.xx:8848/nacos/v1/ns/instance?serviceName=xx&ip=xx&port=xx
服务发现
http://xx.xx.xx.xx:8848/nacos/v1/ns/instance/list?serviceName=xx
客户端启动定时任务每隔10s拉取一次最新的实例列表
服务端也会监听服务的状态,有异常就会基于 UDP 协议反向通知客户端这次服务异常变动
结构
nacos server 中基于 ConcurrentHashMap 作为注册表来放服务信息
ServiceName:实例信息
一致性协议
Raft协议,把注册信息同步给其他节点
安装
https://segmentfault.com/a/1190000038272416
