forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbit.groovy
32 lines (24 loc) · 704 Bytes
/
rabbit.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
}
}