本文整理汇总了Java中reactor.core.Reactor.on方法的典型用法代码示例。如果您正苦于以下问题:Java Reactor.on方法的具体用法?Java Reactor.on怎么用?Java Reactor.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.Reactor
的用法示例。
在下文中一共展示了Reactor.on方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import reactor.core.Reactor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Environment env = new Environment();
Reactor reactor = Reactors.reactor().env(env).dispatcher(Environment.THREAD_POOL).get();
// topic: parse
reactor.on($("parse"), App::handleEvent1);
reactor.on($("parse"), App::handleEvent2);
// Notify consumers of the 'parse' topic that data is ready
// by passing a Supplier<Event<T>> in the form of a lambda
for (long l = 0; true; l++) {
String obj = "Test-" + l;
reactor.notify("parse", Event.wrap(new ObjectEvent().setObject(obj)));
Thread.sleep(1000);
}
}
示例2: main
import reactor.core.Reactor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Environment env = new Environment();
final TradeServer server = new TradeServer();
// Use a Reactor to dispatch events using the default Dispatcher
Reactor reactor = Reactors.reactor()
.env(env)
.dispatcher("ringBuffer")
.get();
String topic = "trade.execute";
// For each Trade event, execute that on the server
reactor.on($(topic), new Consumer<Event<Trade>>() {
@Override
public void accept(Event<Trade> tradeEvent) {
server.execute(tradeEvent.getData());
// Since we're async, for this test, use a latch to tell when we're done
latch.countDown();
}
});
// Start a throughput timer
startTimer();
// Publish one event per trade
for (int i = 0; i < totalTrades; i++) {
// Pull next randomly-generated Trade from server
Trade t = server.nextTrade();
// Notify the Reactor the event is ready to be handled
reactor.notify(topic, Event.wrap(t));
}
// Stop throughput timer and output metrics
endTimer();
server.stop();
}
示例3: reactor
import reactor.core.Reactor; //导入方法依赖的package包/类
@Bean
public Reactor reactor(Environment env, MailServer mailServer) {
Logger log = LoggerFactory.getLogger("mail.server");
Reactor r = Reactors.reactor(env);
// Wire an event handler to execute messages
r.on($("mail.execute"), (Event<MessageDescriptor> ev) -> {
mailServer.execute(ev.getData());
log.info("Executed message: {}", ev.getData());
});
return r;
}