Archive for the Category 'jms'

A Minimal Grails JMS Integration

Thursday, August 28th, 2008

We’re implementing some asynchronous processing at work and naturally JMS seems like the right choice. We looked at the JMS plugin, and it is helpful but you need to configure a JMS provider yourself. It’d certainly be more helpful if it configured a provider for you, e.g. ActiveMQ, while making it easy to configure another if you want.

We were having some classloader issues with ActiveMQ, so I configured a new empty app just to get that working, without the clutter of all of our code, the other various plugins, etc. I thought I had everything working – at least the app started – but although I didn’t get errors sending test messages, I wasn’t seeing any output in the console from the listener I’d configured.

It turns out it was a Groovy issue – I was trying to send a text message but ended up sending a GString, which was sent as an ObjectMessage, so when I called “message.getText()” in onMessage() it failed, and the Spring wrapper class just logs the exception so I didn’t see anything.

So anyway, I thought I’d post the app I created to help others get started. It’s intentionally very basic – it uses an in-memory instance of ActiveMQ (so there’s no extra step of starting an external server) and configures a single queue, plus a single listener and a simple Controller method to send test messages. It doesn’t use the JMS plugin, but Spring’s excellent JmsTemplate makes sending message trivial. Adding other queues, listeners, and senders would be simple by using the existing configuration as a guide.

Download the sample app here. Run “grails run-app” and navigate to http://localhost:8080/jms/jms and you should see a message in the console after the receiver logs the receipt of the message that the JmsController sends.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.