[BS-48] Add autoconfigured JMS support
* Add ability to detect spring-jms on the path and create a JmsTemplate with ActiveMQConnectionFactory * Create tests showing autoconfigured JmsTemplate with ActiveMQ, but prove it backs off if a separate ConnectionFactory exists. * Add support to spring-boot-cli to that it detects JmsTemplate, DefaultMessageListenerContainer, or SimpleMessageListenerContainer, and turns on autoconfiguration as well as add proper @Grab's and import statements. * Write a jms.groovy test showing proper CLI support Simplify ActiveMQ configuration Update ActiveMQ to 5.7.0
This commit is contained in:
committed by
Dave Syer
parent
ecc4676fb3
commit
5801e422cf
48
spring-boot-cli/samples/jms.groovy
Normal file
48
spring-boot-cli/samples/jms.groovy
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.test
|
||||
|
||||
@Grab("org.apache.activemq:activemq-all:5.2.0")
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
@Configuration
|
||||
@Log
|
||||
class JmsExample implements CommandLineRunner {
|
||||
|
||||
private CountDownLatch latch = new CountDownLatch(1)
|
||||
|
||||
@Autowired
|
||||
JmsTemplate jmsTemplate
|
||||
|
||||
@Bean
|
||||
DefaultMessageListenerContainer jmsListener(ConnectionFactory connectionFactory) {
|
||||
new DefaultMessageListenerContainer([
|
||||
connectionFactory: connectionFactory,
|
||||
destinationName: "spring-boot",
|
||||
pubSubDomain: true,
|
||||
messageListener: new MessageListenerAdapter(new Receiver(latch:latch)) {{
|
||||
defaultListenerMethod = "receive"
|
||||
}}
|
||||
])
|
||||
}
|
||||
|
||||
void run(String... args) {
|
||||
def messageCreator = { session ->
|
||||
session.createObjectMessage("Greetings from Spring Boot via ActiveMQ")
|
||||
} as MessageCreator
|
||||
log.info "Sending JMS message..."
|
||||
jmsTemplate.pubSubDomain = true
|
||||
jmsTemplate.send("spring-boot", messageCreator)
|
||||
latch.await()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Log
|
||||
class Receiver {
|
||||
CountDownLatch latch
|
||||
|
||||
def receive(String message) {
|
||||
log.info "Received ${message}"
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user