Previously, simple @Grab annotations only worked on classes. This commit updates the simple @Grab support so that they can be used on anything that can be annotated with @Grab. The simplified @Grab support relies upon springcli.properties having been generated. This commit adds an M2E lifecycle mapping for the antrun plugin so that springcli.properties is generated as part of an Eclipse build, thereby making it easier to run tests in Eclipse that rely upon the simplified @Grab support.
49 lines
1.1 KiB
Groovy
49 lines
1.1 KiB
Groovy
package org.test
|
|
|
|
@Grab("org.apache.activemq:activemq-all:5.4.0")
|
|
@Grab("activemq-pool")
|
|
import java.util.concurrent.CountDownLatch
|
|
|
|
@Log
|
|
@Configuration
|
|
@EnableJmsMessaging
|
|
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.send("spring-boot", messageCreator)
|
|
latch.await()
|
|
}
|
|
|
|
}
|
|
|
|
@Log
|
|
class Receiver {
|
|
CountDownLatch latch
|
|
|
|
def receive(String message) {
|
|
log.info "Received ${message}"
|
|
latch.countDown()
|
|
}
|
|
}
|