Friday, January 31, 2014

Sending ActiveMQ messages from Groovy

Didn't found it in Google, so there is quick example how to send JMS message from Groovy script using Grab:


@Grab(group='org.apache.activemq',module = 'activemq-all', version='5.5.0')

import org.apache.activemq.ActiveMQConnectionFactory
import javax.jms.Session

new ActiveMQConnectionFactory(brokerURL: 'tcp://localhost:61616').createConnection().with {
  start()
  createSession(false, Session.AUTO_ACKNOWLEDGE).with {
    createProducer().send(createQueue("queue"), createTextMessage("test"))
  }
  close()
}


2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Nice and clean! How about "Receiving ActiveMQ messages from Groovy" using your same coding structure?

    ReplyDelete