FFL*_*FFL 3 java spring reactor
使用reactor(https://github.com/reactor/reactor)我通知一些事件,如
commandReactor.notify("CREATE_CUSTOMER", Event.wrap(customer));
commandReactor.notify("CREATE_ORDER", Event.wrap(order));
Run Code Online (Sandbox Code Playgroud)
如何实现选择以"CREATE"开头的所有事件的选择器?就像是
@Selector(value = "CREATE*", reactor = "@commandReactor")
Run Code Online (Sandbox Code Playgroud)
提前致谢.
小智 7
你可以使用RegexSelector[1]来做到这一点:
commandReactor.notify("CREATE_(.+)", Event.wrap(obj));
Run Code Online (Sandbox Code Playgroud)
或者,使用注释:
@Selector(value = "CREATE_(.+)", type = SelectorType.REGEX)
Run Code Online (Sandbox Code Playgroud)
然后在你的处理器,你可以在头寻找检查捕获组group1到groupN:
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
}
}
Run Code Online (Sandbox Code Playgroud)
[1] - http://reactor.github.io/docs/api/reactor/event/selector/RegexSelector.html