Thursday, February 24, 2011

JMS and Async, Dont mess with it

JMS stands for Java Message Service which is an API which is used by middle ware service providers such as ActiveMQ, JBoss MQ, Rabbit MQ etc etc. Its main purpose is to allow disparate systems to communicate based on a common platform. Which means that if i have my front end written in .Net and my back end written in Java for example one way of communicating between the two (other than Webservices etc) is to use a JMS provider in a publisher-subscriber or peer-to-peer configuration.

In our own project we have used JMS but not to communicate between two disparate systems but to get the asynchronous capability integrated to our application. What we do is push the message into a queue and get along with the rest of the business process. But from what i see this is not the correct way of achieving this. Of course at the end of the day we have achieved asynchronous behavior but not in the right way. A solution just came to light a few months back with the release of Spring 3. Spring 3 provided an implementation allowing asynchronous capability with the @Async annotation. I will not go into the details of this feature as it is very well explained here.


I have changed the previously JMS oriented code which mimicked the asynchronous capability and introduced Spring's Async implementation as i felt it was much cleaner and reduced all handling i needed to do with onMessage(),Connection Factory and the rest of the code needed to deal with JMS queues and topics.


4 comments:

  1. You don't need Spring for this. Java already has the @Asynchronous annotation. Put it on a bean's method and it instantly executes asynchronously ;)

    ReplyDelete
  2. Hi Thx for ur comment. But thing is @Asynchronous comes with ejb 3.1 spec. And right now there are very few Application servers that support that spec yet. So to all those other people this is the only viable solution i see :) ... Cheers

    ReplyDelete
  3. What about Glassfish, JBoss AS and Resin? They all support it. Together these are the majority of the app server market. For the important servers, only Websphere is missing.

    ReplyDelete
  4. Yes that is true. Jboss AS only supports the ejb 3.1 spec from Jboss 5 as i know. Im talking about a generalized approach. Rather than changing your current application server you just have to upgrade to Spring 3 which is a less hassle as i believe.

    ReplyDelete