mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
48 lines
667 B
Groovy
48 lines
667 B
Groovy
package org.test
|
|
|
|
import java.util.concurrent.CountDownLatch
|
|
|
|
@EnableReactor
|
|
@Log
|
|
class Runner implements CommandLineRunner {
|
|
|
|
@Autowired
|
|
EventBus eventBus
|
|
|
|
private CountDownLatch latch = new CountDownLatch(1)
|
|
|
|
@PostConstruct
|
|
void init() {
|
|
log.info "Registering consumer"
|
|
}
|
|
|
|
void run(String... args) {
|
|
eventBus.notify("hello", Event.wrap("Phil"))
|
|
log.info "Notified Phil"
|
|
latch.await()
|
|
}
|
|
|
|
@Bean
|
|
CountDownLatch latch() {
|
|
latch
|
|
}
|
|
|
|
}
|
|
|
|
@Consumer
|
|
@Log
|
|
class Greeter {
|
|
|
|
@Autowired
|
|
EventBus eventBus
|
|
|
|
@Autowired
|
|
private CountDownLatch latch
|
|
|
|
@Selector(value="hello")
|
|
void receive(String data) {
|
|
log.info "Hello ${data}"
|
|
latch.countDown()
|
|
}
|
|
|
|
} |