Thursday, July 26, 2012

JMS (with) Spring and Apache ActiveMQ

0. Introduction

If you have worked with Java EE or you are willing to work with it, you probably have heard about Apache Active MQ. Since, for some reason, nearly each and every blog post that I have read on JMS and Spring (Including Spring In Action (Third Edition) and Just Spring (First Edition)) are using ActiveMQ. ActiveMQ is also recommended to be used while developing Java EE applications with Spring Framework.

So let us briefly explore what are advantages and disadvantages of using ApacheMQ.

First question that comes to mind is why it is so popular. apparently, you have variety of options as the following list proposes:
source: Wikipedia,

ActiveMQ seems to be quiet a popular option. As Aron Mulder mentioned in SpringSource webinar (Webinar Slides): it is open-source and community-based (as compared to JBoss MQ), its performance in being able to run standalone, or equally inside another process, application server, or Java EE application, its support for nearly everything JMS requires, and lastly its various extensions that integrates well into other products. Apart from what was mentioned in the Webinar, a key benefit of using ActiveMQ with Spring is that, Spring introduced  DefaultMessageListenerContainer object from API 2.0 and with that you only need to define an onMessage method where you can easily enable batch processing.

On disadvantages side, ActiveMQ can decrease performance, if you are not using a connection pool. As JmsTemplate asks for a connection per message and then closes it, therefore can put a huge processing load on the server.

1 comment: