Jump to content

Groovy script to post text to an ActiveMQ JMS


This topic is 1610 days old. Please don't post here. Open a new topic instead.

Recommended Posts

 
And then here's the groovy code…
 
RegisterGroovy( "sendToJMS( qURL ; qSubject ; qMessage  )" ;


"import javax.jms.*;¶
import org.apache.activemq.*;¶


ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(qURL);¶
Connection connection = connectionFactory.createConnection();¶
connection.start();¶

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);¶
Destination destination = session.createQueue(qSubject);¶

MessageProducer producer = session.createProducer(destination);¶
TextMessage message = session.createTextMessage(qMessage);¶
producer.send(message);¶

connection.close();¶
return true;"; "isGui=false" )

You get back '1'/true for success or 'ERROR' for a failure to post the message.

 

Amazed about how easy that was to get done, and I'm just posting in case this is useful to anyone else. (It's entirely cribbed code from a java primer page I found online)

Link to comment
Share on other sites

  • 2 years later...

This topic is 1610 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.