-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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-Client 升级到 2.1.1 导致实例订阅事件失效 #9227
Comments
ruansheng8
changed the title
Nacos 2.0.4 升级到 2.1.1 导致实例订阅事件失效
Nacos-Client 2.0.4 升级到 2.1.1 导致实例订阅事件失效
Sep 28, 2022
看起来是修复默认Subscriber的行为就可以了 |
欢迎提一个PR修复 |
ruansheng8
changed the title
Nacos-Client 2.0.4 升级到 2.1.1 导致实例订阅事件失效
Nacos-Client 升级到 2.1.1 导致实例订阅事件失效
Sep 28, 2022
KomachiSion
pushed a commit
that referenced
this issue
Sep 28, 2022
Fixed #9233 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
A clear and concise description of what the bug is.
Nacos-Client version : 2.1.1
Actually behavior
使用 nacos-client 2.0.4 版本进行事件订阅可正常收到实例的变更 , 升级到 nacos-client 2.1.1 会导致其订阅失效
How to Reproduce
原因
排查后发现是由于解决 #8433 这个issue导致的 , 该Issue增加了eventScope唯一标识来区分事件不同的域 , 并且给 com.alibaba.nacos.common.notify.listener.Subscriber 这个抽象类增加了一个scopeMatches 方法 , 该方法不是抽象的 , 以前所有旧版本升级到2.1.1版本后 , 开发者并不知道去重写该方法 , 导致了订阅失效
以下是Subscriber 新增的方法 , 默认判断event.scope() == null 的情况事件生效 , 当时框架创建的InstancesChangeEvent中的eventScope永远不为空 (默认是在创建的时候给了一个UUID) , 从而导致自定义的订阅事件没有重写scopeMatches方法的话结果永远是false
部分源码: NacosNamingService.java
部分源码: ServiceInfoHolder.java
部分源码: DefaultPublisher.java
Bug复现
以下是复现的代码 , 通过切换本地的nacos-client 版本 , 2.0.4 版本可以正常收到实例变更事件 , 2.1.1 版本不行
解决方案
重写Subscriber 的scopeMatches方法 , 返回true时生效
The text was updated successfully, but these errors were encountered: