Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nacos Discovery] Add configuration properties to decide poll or not poll the subscription service. #661

Open
fangjian0423 opened this issue May 22, 2019 · 5 comments
Labels
area/nacos spring cloud alibaba nacos kind/discussion Mark as discussion issues/pr

Comments

@fangjian0423
Copy link
Contributor

fangjian0423 commented May 22, 2019

Which Component

Nacos Discovery

Is your feature request related to a problem? Please describe.

Now nacos discovery starter will always poll the subscription service until it can subscribe when service is not exists.

Refer the method List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException; of NamingService.

We can choose the other method List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException; to not poll the subscription service when service is not exists.

Describe the solution you'd like

Add an configuration properties boolean subscribe; in NacosDiscoveryProperties to decide poll or not poll the subscription service.

@fangjian0423 fangjian0423 added kind/discussion Mark as discussion issues/pr area/nacos spring cloud alibaba nacos labels May 22, 2019
@caojianqiang1984
Copy link

@fangjian0423
对于您的建议

We can choose the other method List selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException; to not poll the subscription service when service is not exists.

Add an configuration properties boolean subscribe; in NacosDiscoveryProperties to decide poll or not poll the subscription service.

请考虑如下几点:

  1. 对于Spring的DiscoveryClient接口,暴露的是getInstances方法。而这个接口的nacos实现类NacosDiscoveryClient在getInstances方法中,已经写死了使用List selectInstances(String serviceName, boolean healthy)方法,我并没有办法修改成您建议的List selectInstances(String serviceName, boolean healthy, boolean subscribe)。
  2. 即使是使用List selectInstances(String serviceName, boolean healthy, boolean subscribe),最后的参数如果传true,那跟之前无异,在serviceName不存在的时候(可能前端传错,也可能服务已经下线),会每隔1秒刷找不到服务日志;如果最后参数传false,那将直接从nacos服务器获取服务信息,并不会读取本地缓存的服务实例数据,这显然不是一个DiscoveryClient应该有的行为。
  3. NacosDiscoveryProperties并没有subscribe属性。无法像您建议的修改配置。我的版本是org.springframework.cloud:spring-cloud-alibaba-nacos-discovery:0.9.0.RELEASE

@fangjian0423
Copy link
Contributor Author

@caojianqiang1984

这个 issue 还在讨论阶段,所以代码层面还没有动过。

其实我觉得这个问题,只要找不到服务不要报 404 错误就可以了,服务中心专注于做自己的事,直接节点数为0,怎么处理,是上层应该关系的事情,不应该和上层的逻辑杂糅在一起。

@caojianqiang1984
Copy link

@fangjian0423 不关服务中心的事情,服务不存在服务中心返回404是正常的。但是在DiscoveryClient这一端,只要调用discoveryClient的getInstances方法去获取一个不存在的服务A时,DiscoveryClient这一端就不断刷日志。原来是DiscoveryClient每隔一秒就偿试去更新这服务A的消息,所以每隔一秒就会刷一次日志,而这个定时任务是白跑的,因为服务A永远都不会存在。

@fangjian0423
Copy link
Contributor Author

fangjian0423 commented May 23, 2019

这个 DiscoveryClient(NacosDiscoveryClient) 的 getInstances 方法调用的是 List<Instance> selectInstances(String serviceName, boolean healthy) throws NacosException; 方法。

这个方法底层是调用另外一个方法,且 subscribe 属性为 true。 List<Instance> selectInstances(String serviceName, boolean healthy, boolean subscribe) throws NacosException;

subscribe 属性为 true 表示是一直轮询订阅服务直到订阅到(如果服务不存在,naming.log 刷日志)。

Spring Cloud 自身是不存在定时�跑刷日志的任务的。

@caojianqiang1984
Copy link

@fangjian0423
我知道是naming在刷日志,再具体点是HostReactor在刷日志。但偿试获取一个不存在的服务信息(调用discoveryClient的getInstances方法),这是个正常的场景,不应该因为偿试获取一个不存在的服务信息而不断的刷日志,更具体一点,不应因为偿试获取了一个不存在的服务信息,HostReactor就生成一个定时任务不断去获取这个不存在服务的信息。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nacos spring cloud alibaba nacos kind/discussion Mark as discussion issues/pr
Projects
None yet
Development

No branches or pull requests

2 participants