This page is kept for archive. Please visit the GroovyJMS doc page for the latest documentation.
Let's start with some examples first:
ConnectionFactory jms = new ActiveMQConnectionFactory(brokerURL: "vm://localhost"); |
use(JMS){
jms.topic("greeting").subscribe({Message m \-> println "hey i got a message. it says, '${m.text}'"} as MessageListener);
jms.close(); //optional
}
|
use(JMS) {
jms.topic("greeting").send("I'm joining the JMS party"); // use jms.queue("greeting queue") for sending to a queue
jms.close(); //optional
}
|
use(JMS){
Message message = jms.queue("greeting").receive(1000); // it does \*not\* mean get 1,000 message, see the note below this box
List<Message> messages = jms.queue("greeting").receiveAll(1000); // this retrieve all messages within the 1000ms timeout interval
jms.close(); //optional
}
|
// the first guy
use(JMS){
Queue replyQueue = jms.session().createQueue("replyQueue"); // notice that createQueue is the original JMS API, it's just an example, u could use jms.queue("replyQueue")
jms.queue("greeting").send("hey, please reply to me privately", [JMSCorrelationID: 'privatePlease', JMSReplyTo: replyQueue])
jms.close(); //optional
}
// another guy in another thread
use(JMS){
jms.queue("greeting").receive(1000)?.with{
// please do something here, otherwise the example does not make sense
it.reply("hey, let me tell you secretly")
};
jms.close(); //optional
}
|
def Connection jmsConnection;
use(JMS){
jmsConnection = jms.connect();
jms.cleanupThreadLocalVariables(); //clear all ThreadLocal variables
}
|
//no need the "use(JMS)" for this case Connection connectioin = JMS.connection.get(); Session session = JMS.session.get(); |
jms.queue("myQueue")
jms.connect().queue("myQueue")
Connection conn = jms.connect(); conn.queue("myQueue")
jms.session().queue("myQueue")
// but no jms.connect().session().queue("myQueue"); it's too much\! Please use the JMS createSession() api
|
conn.setExceptionListener({JMSException e \-> logger.error("JMS Exception", e)} as ExceptionListener);
|
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.1.0.xsd">
<amq:broker useJmx="false" persistent="false">
<amq:transportConnectors>
<amq:transportConnector uri="vm://localhost"/>
</amq:transportConnectors>
</amq:broker>
<amq:connectionFactory id="connectionFactory" brokerURL="vm://localhost"/>
|
And you'll need the following jars:
For ActiveMQ core: activemq-all-*.jar // tested with activemq-all-5.3-SNAPSHOT.jar only For Spring AMQ prefix: xbean-spring-2.6 activeio-core.jar (it's not needed if you don't use the io persitence) |