You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
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
|
|
|
|
Queue queue() {
|
|
|
|
new Queue("spring-boot", false)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|