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.
32 lines
618 B
Groovy
32 lines
618 B
Groovy
11 years ago
|
package org.test
|
||
|
|
||
|
import java.util.concurrent.CountDownLatch
|
||
|
|
||
|
@Log
|
||
|
@Configuration
|
||
10 years ago
|
@EnableRabbit
|
||
11 years ago
|
class RabbitExample implements CommandLineRunner {
|
||
|
|
||
11 years ago
|
private CountDownLatch latch = new CountDownLatch(1)
|
||
|
|
||
|
@Autowired
|
||
|
RabbitTemplate rabbitTemplate
|
||
|
|
||
|
void run(String... args) {
|
||
|
log.info "Sending RabbitMQ message..."
|
||
10 years ago
|
rabbitTemplate.convertAndSend("spring-boot", "Greetings from Spring Boot via RabbitMQ")
|
||
11 years ago
|
latch.await()
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
@RabbitListener(queues = 'spring-boot')
|
||
11 years ago
|
def receive(String message) {
|
||
|
log.info "Received ${message}"
|
||
|
latch.countDown()
|
||
|
}
|
||
10 years ago
|
|
||
|
@Bean
|
||
|
Queue queue() {
|
||
|
new Queue("spring-boot", false)
|
||
|
}
|
||
|
|
||
|
}
|