2013-07-24 21:56:30 +08:00
|
|
|
package org.test
|
|
|
|
|
2014-05-29 20:20:20 +08:00
|
|
|
import java.util.concurrent.CountDownLatch
|
2013-07-31 05:03:56 +08:00
|
|
|
|
2013-07-24 21:56:30 +08:00
|
|
|
@EnableReactor
|
|
|
|
@Log
|
|
|
|
class Runner implements CommandLineRunner {
|
2013-11-05 14:02:20 +08:00
|
|
|
|
2013-07-24 21:56:30 +08:00
|
|
|
@Autowired
|
2015-04-27 20:47:42 +08:00
|
|
|
EventBus eventBus
|
2013-11-05 14:02:20 +08:00
|
|
|
|
2013-07-31 05:03:56 +08:00
|
|
|
private CountDownLatch latch = new CountDownLatch(1)
|
2013-11-05 14:02:20 +08:00
|
|
|
|
2013-07-31 05:03:56 +08:00
|
|
|
@PostConstruct
|
|
|
|
void init() {
|
|
|
|
log.info "Registering consumer"
|
|
|
|
}
|
2013-07-24 21:56:30 +08:00
|
|
|
|
|
|
|
void run(String... args) {
|
2015-04-27 20:47:42 +08:00
|
|
|
eventBus.notify("hello", Event.wrap("Phil"))
|
2013-07-24 21:56:30 +08:00
|
|
|
log.info "Notified Phil"
|
2013-07-31 05:03:56 +08:00
|
|
|
latch.await()
|
2013-07-24 21:56:30 +08:00
|
|
|
}
|
2013-11-05 14:02:20 +08:00
|
|
|
|
2014-05-29 20:20:20 +08:00
|
|
|
@Bean
|
|
|
|
CountDownLatch latch() {
|
|
|
|
latch
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Consumer
|
|
|
|
@Log
|
|
|
|
class Greeter {
|
|
|
|
|
|
|
|
@Autowired
|
2015-04-27 20:47:42 +08:00
|
|
|
EventBus eventBus
|
2014-05-29 20:20:20 +08:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CountDownLatch latch
|
|
|
|
|
2014-04-30 18:26:57 +08:00
|
|
|
@Selector(value="hello")
|
2013-08-29 17:38:35 +08:00
|
|
|
void receive(String data) {
|
|
|
|
log.info "Hello ${data}"
|
|
|
|
latch.countDown()
|
2013-11-05 14:02:20 +08:00
|
|
|
}
|
2014-05-29 20:20:20 +08:00
|
|
|
|
|
|
|
}
|