mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
32 lines
704 B
Groovy
32 lines
704 B
Groovy
package org.test
|
|
|
|
import java.util.concurrent.CountDownLatch
|
|
|
|
@Log
|
|
@Configuration(proxyBeanMethods = false)
|
|
@EnableRabbit
|
|
class RabbitExample implements CommandLineRunner {
|
|
|
|
private CountDownLatch latch = new CountDownLatch(1)
|
|
|
|
@Autowired
|
|
RabbitTemplate rabbitTemplate
|
|
|
|
void run(String... args) {
|
|
log.info "Sending RabbitMQ message..."
|
|
rabbitTemplate.convertAndSend("spring-boot", "Greetings from Spring Boot via RabbitMQ")
|
|
latch.await()
|
|
}
|
|
|
|
@RabbitListener(queues = 'spring-boot')
|
|
def receive(String message) {
|
|
log.info "Received ${message}"
|
|
latch.countDown()
|
|
}
|
|
|
|
@Bean
|
|
org.springframework.amqp.core.Queue queue() {
|
|
new org.springframework.amqp.core.Queue("spring-boot", false)
|
|
}
|
|
|
|
} |