One of the best way to link together different parts of your application environment is to use asynchronous messaging. And the standard way to do this with Java is JMS. And one of the most popular tools for developing JMS messaging applications is ActiveMQ. Here we will discuss JMS messaging with and provide some ActiveMQ examples that make this easy to work with.
JMS, the Java Message Service is the API for manipulating messages between components and systems. Messaging is the linking of components, but in this case those components are loosely coupled, as an agent is used as a go between. So the source and target of the messages dont actually have to be available at the same time or even have knowledge of the others interface to communicate. This makes messaging a great method to use for communication between components and systems.
JMS provides a standard set of tools and interfaces that let easily you communicate between components and systems. The 2 main advantages of JMS messaging is that it provides the following facilities. Firstly that the communications between sender and receiver can be asynchronous. In other words both sender and receiver do not need to be available at the same time to send or receive messages. Secondly that the facilities provided are reliable and that once a message is sent it is guaranteed to be made available to the client once the client is ready to receive.
Jms messaging uses a layer of middleware to act and the intermediary, gateway or broker between your components or systems. This middleware cam be simple and just act as a store and forward between your components or can be complex and provide additional services such as mapping, or logging etc.
Some of the popular middleware tools are activemq and openmq in the open source arena, or enterprise ready products such as IBM websphere mq.
For our examples here we will use activemq. Activemq is widely deployed and used in conjunction with many different languages. This means that although the examples here are in java the concepts should still hold true for most environments. Activemq is also very easy to use in unit tests such as junit so makes it simple to write tests for your messaging components whether they talk to activemq or another product.
Testing JMS with Hermes JMS and ActiveMQ
A great tool for testing your JMS implementation and JMS providers is HermesJMS. HermesJMS is a handy open source console app that makes it very easy to interact with your JMS endpoints and do stuff like view and manipulate queues and topics and the messages within them.
You can even copy, post and delete messages with it making it a really handy tool for testing your JMS apps too.
It works with many of the popular JMS providers such as WebLogic JMS, WebMethods,WebSphere MQ, Active MQ, Arjuna MQ, Tibco EMS, Fiorano MQ, JBoss MQ, JORAM, OpenJMS, Oracle, Pramati, SAP, SeeBeyond ICAN, SeeBeyond JCAPS, Sonic MQ