NewInstancer(client Client, logger log.Logger, service string, tags []string, passingOnly bool):
a>首先初始化cache
b>调用 getInstances[s.client.Service获取所有services,然后通过tag进行过滤,过滤后生成格式为[addr:port]的字符串切片]
c>获取完 instances之后,就更新cache,,,

d> 如果获得的实例与cache保存的不一致,则更新,并对注册过的所有服务进行广播。
e> 最后启动go协程,每隔10ms就去重新获取下instance,并更新cache。

NewEndpointer(src Instancer, f Factory, logger log.Logger, options ...EndpointerOption) *DefaultEndpointer:
src.Register(se.ch) 注册到instance上,刚注册就会发送当前实例的Event(包含地址)。
go se.receive() 启动go协程,不断地接收最新的实例地址,并对endpointCache进行更新。

实操:

网友评论