spring-boot/spring-boot-cli/samples/reactor.groovy

48 lines
667 B
Groovy
Raw Normal View History

package org.test
import java.util.concurrent.CountDownLatch
2013-07-31 05:03:56 +08:00
@EnableReactor
@Log
class Runner implements CommandLineRunner {
2013-11-05 14:02:20 +08:00
@Autowired
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"
}
void run(String... args) {
eventBus.notify("hello", Event.wrap("Phil"))
log.info "Notified Phil"
2013-07-31 05:03:56 +08:00
latch.await()
}
2013-11-05 14:02:20 +08:00
@Bean
CountDownLatch latch() {
latch
}
}
@Consumer
@Log
class Greeter {
@Autowired
EventBus eventBus
@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
}
}