gpt4 book ai didi

java - 使用 Reactor 选择与键匹配的事件

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:27:37 24 4
gpt4 key购买 nike

使用 reactor( https://github.com/reactor/reactor ) 我通知一些事件,比如

 commandReactor.notify("CREATE_CUSTOMER", Event.wrap(customer));
commandReactor.notify("CREATE_ORDER", Event.wrap(order));

我如何实现一个选择器来选择所有以“CREATE”开头的事件?有点像

@Selector(value = "CREATE*", reactor = "@commandReactor")

提前致谢。

最佳答案

您可以使用 RegexSelector [1] 来做到这一点:

    commandReactor.notify("CREATE_(.+)", Event.wrap(obj));

或者,使用注解:

    @Selector(value = "CREATE_(.+)", type = SelectorType.REGEX)

然后在您的处理程序中,您可以通过查看 group1groupN 的 header 来检查捕获组:

new Consumer<Event<Object>>>() {
public void accept(Event<?> ev) {
String type = ev.getHeaders().get("group1");
if("CUSTOMER".equals(type)) {
// handle customers
} else if("ORDER".equals(type)) {
// handle orders
}
}

[1] - http://reactor.github.io/docs/api/reactor/event/selector/RegexSelector.html

关于java - 使用 Reactor 选择与键匹配的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19790051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com