Java Message Queuing (Continued)

Regular readers of this blog will know I’ve struggled with Java and Message Queuing (see blog posts here, here, here and here). Normally by this point I would have given up, but having used Message Queuing to integrate a number of systems in a Microsoft world I really understand and appreciate the power of them when done properly.

So yesterday I returned to the issue. Having listened to This Developers Life podcast about the downtime at StackOverflow I decided StackOverflow was a resource I was aware of, but had never really used (other than via the occasional Google result). I searched StackOverflow for information on Java Message Queuing, and go directed towards OpenMQ.

Heading back to Google I found a couple of useful articles about using OpenMQ and from the contents of both managed to get myself sending messages to a local GlassFish instance. However, I’m fairly certain I’d be able to alter this code slightly to send to a remote machine – just something I don’t currently have the capabilities (or the pressing need) to confirm.

As per most of my posts, this is primarily for my own reference when I need to return to it at some point in the future – but it may prove of use to others.

The two resources of particular use were: and

The actual code that worked for sending a message for me was:

public static void main(String[] args) throws JMSException {
   com.sun.messaging.ConnectionFactory connectionFactory = new com.sun.messaging.ConnectionFactory();
   javax.jms.QueueConnection queueConnection = connectionFactory.createQueueConnection("xxx", "xxx");
   javax.jms.QueueSession queueSession = queueConnection.createQueueSession(false,
   javax.jms.Queue smsQueue = queueSession.createQueue("gbTestQueue");
   javax.jms.MessageProducer producer = queueSession.createSender(smsQueue);
   Message msg = queueSession.createTextMessage("A sample sms message");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s