-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Support service change event #2733
Conversation
1. 服务变化信息其实是通过pushReceiver接收并调用注入的hostReactor解析json信息并触发对应的变化分析逻辑 2. 此处加入分析后事件发布逻辑, 实质上是调用客户端自定义实现的监听逻辑,此逻辑不应耗时过长,否则将导致ack响应延迟。 3. 增加EventInvoker之后 无论是基于spring boot或者是spring cloud模式都可以自定义一个实现类针对不同的事件类型实现对应的业务逻辑, 建议使用spring Application event机制进行定制。
|
if the PR be accept, for Nacos Spring Cloud Projects, we can add a eventpublisher and a evenlister as this simple spring event listener example, which u can very free to design for your client project story.
what we need is just to find a agent way to set your EventPublisher to HostReactor.
|
You just need to add an Event and reuse the EventDispatcher, it doesn't have to be that complicated |
Do you mean to listen to a namingEvent as this example?
i know that EventDispatcher will pushlish namingEvent for changeService, but in issue 2133 what they need is a global event which not need to set a special service and other params. nacos/client/src/main/java/com/alibaba/nacos/client/naming/core/EventDispatcher.java Lines 129 to 134 in 4baaef4
maybe something like zookeeper watcher. This is a zookeeper watcher example (随手百度第一个).
This PR is a normal design like other Service Registry and their client. |
|
他们现在应该是基于许长老的使用Nacos实现Spring Cloud Gateway的动态路由| 去做的 |
可以说在NamingService添加一个方法,subscribeGlobalService,重新创建一个事件类型就好了,不必要添加一个EventPublisher,并且在nacos-client有一些东西不要暴露出去,比如HostReactor, |
我本来的想法是如此,但是后来想把接口暴露出去,让他们自己针对自己的业务实现一套发布和监听逻辑会不会更好。可以基于spring event去做(好管理,容易适配),又可以自己定义一个机制,基于队列和生成者消费者模型去做,publish的时候只是把事件放到队列中然后异步返回,有一个listenContainer来处理这个队列里的事件,这样的自由度就很高了,完全基于业务定制,而不是像现在直接去invoke onEvent,也许这个需求并没有复杂到这个程度。 |
目前PR中的方式确实不够优雅,而且setEventPublisher是在构造函数即init逻辑设置之后进行的,严格来讲会有问题。 |
这类就不要涉及任何spring的实现了,任何客户端的操作,都通过NamingService
2020年5月5日 下午6:15,maketubo <[email protected]<mailto:[email protected]>> 写道:
我本来的想法是如此,但是后来想把接口暴露出去,让他们自己针对自己的业务实现一套发布和监听逻辑会不会更好。可以基于spring event去做(好管理,容易适配),又可以自己定义一个机制,基于队列和生成者消费者模型去做,publish的时候只是把事件放到队列中然后异步返回,有一个listenContainer来处理这个队列里的事件,这样的自由度就很高了,完全基于业务定制,而不是像现在直接去invoke onEvent,也许这个需求并没有复杂到这个程度。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#2733 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFS35NEQ5NZULSWSUO6OQNDRP7RMVANCNFSM4MY3533A>.
|
@chuntaojun 很遗憾你没懂我的意思 |
我觉得你把这个需求弄的过于复杂了,我的想法就只有一个,多一个Event类型和一个subscribe类型,没有其他额外的东西,因为我觉得你的设计中,外引入了一个publisher和subscriber,这对于我们后面的统一事件机制模式并不友好,而且我希望你在设计中,任何的操作,都是通过namingService去做,而不是在namingService提供的方法之外,就比如你说的接口暴露出去,这不是我所希望看到的
2020年5月5日 下午6:45,maketubo <[email protected]<mailto:[email protected]>> 写道:
@chuntaojun<https://github.com/chuntaojun> 很遗憾你没懂我的意思
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#2733 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFS35NBJ7EK4BJUDYM6UU7DRP7U3PANCNFSM4MY3533A>.
|
至少对于目前的实现来说,我觉得并不好,期待你的重新提交 |
我想我明白你的意思了,可能是表述和理解上的差异。我的事件切入点在PushReceiver收到消息的时候, |
你的意思应该是以下的伪代码,应该要在EventDispatcher维护一个以GlobalEventType为key的listener列表就可以。
|
关于怎么触发各种类型的回调,可以看看这个 public abstract class TestEventListener implements EventListener {
@Override
public final void onEvent(Event event) {
if (event instanceof GlobalEvent) {
GlobalEvent globalEvent = (GlobalEvent) event;
int type = globalEvent.getType();
switch (type) {
case 1:
onServiceRegister(globalEvent);
break;
case 2:
onServiceDown(globalEvent);
break;
case 3:
onServiceModify(globalEvent);
break;
case 4:
onServiceNormal(globalEvent);
break;
default:
throw new IllegalArgumentException();
}
}
}
protected void onServiceRegister(GlobalEvent event) {
}
protected void onServiceDown(GlobalEvent event) {
}
protected void onServiceModify(GlobalEvent event) {
}
protected void onServiceNormal(GlobalEvent event) {
}
} |
关于可能的改动点,可能如下
接下来就是在 Notifier 遍历监听GlobalEvent的listener列表触发他们的onEvent了。 @chuntaojun 看到你提供的那个PR上的改动 觉得等那个PR的提交合到基线版本上再进行这个issue的处理也不迟。 其实我也想了一下,我的PR其实方向错了,其实我的意思,应该是给EventDispatcher抽象成一个接口,框架内部提供的只是默认的实现,外部可以重定义这个EventDispatcher,实现自己的发布逻辑,而无需再去定义一个eventPublisher。 |
#2133 What is the purpose of the change
to give a api to listen special event like (service remove, service register or just service info change).
Brief changelog
XX
Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.