mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
32 lines
748 B
Groovy
32 lines
748 B
Groovy
@Grab("spring-boot-starter-artemis")
|
|
@Grab("artemis-jms-server")
|
|
import java.util.concurrent.CountDownLatch
|
|
|
|
@Log
|
|
@Configuration(proxyBeanMethods = false)
|
|
@EnableJms
|
|
class JmsExample implements CommandLineRunner {
|
|
|
|
private CountDownLatch latch = new CountDownLatch(1)
|
|
|
|
@Autowired
|
|
JmsTemplate jmsTemplate
|
|
|
|
void run(String... args) {
|
|
def messageCreator = { session ->
|
|
session.createObjectMessage("Greetings from Spring Boot via Artemis")
|
|
} as MessageCreator
|
|
log.info "Sending JMS message..."
|
|
jmsTemplate.send("spring-boot", messageCreator)
|
|
log.info "Send JMS message, waiting..."
|
|
latch.await()
|
|
}
|
|
|
|
@JmsListener(destination = 'spring-boot')
|
|
def receive(String message) {
|
|
log.info "Received ${message}"
|
|
latch.countDown()
|
|
}
|
|
|
|
}
|