Nacos 服务推送和发现

Nacos 注册中心原理:

 

一: 发布

1、服务注册发布 代码

@Service
@SofaService(
        bindings = {
                @SofaServiceBinding(bindingType = "jvm"),
                @SofaServiceBinding(bindingType = "bolt")
        }
)public class FlowRuleServiceImpl implements FlowRuleService {

服务注册,是让服务在本地启动, 将启动服务的信息推送到注册中心(地址、通信协议、接口 等服务实例信息)。

 

2、这里是服务推送。

使用的是 @SofaService 注解;

@SofaServiceBinding(bindingType = "bolt") 代表服务调用用使用的协议。

 

二:请求调用

@SofaReference(
        binding = @SofaReferenceBinding(bindingType = "bolt")
)
protected FlowRuleService flowRuleService;

@SofaReference 是引用远端服务请求,添加上 bindingType = “bolt”, 代表了,请求远端服务时用的通信协议。

这里的过程就是先从 注册中心拉取 请求服务的配置信息,然后根据拉到的服务实例信息 请求实例。

 

如果是 本地的(本服务器)实例服务,可以不添加 bindingType = "bolt"(通信协议) 也可以请求到实例。

 

扩展:

还有 interfaceType 参数

@SofaReference(interfaceType = ProductModelService.class)

此参数将调用类进行接口指定,

 

扩展:

简单介绍:

 

分级存储模型

 

配置中心原理:

 

 

 

原文地址:https://www.cnblogs.com/wgy1/p/14706246.html