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.
spring-boot/spring-boot-cli/samples/jms.groovy

34 lines
740 B
Groovy

package org.test
@Grab("spring-boot-starter-artemis")
@Grab("artemis-jms-server")
import java.util.concurrent.CountDownLatch
@Log
@Configuration
@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')
11 years ago
def receive(String message) {
log.info "Received ${message}"
latch.countDown()
}
10 years ago
}