Saturday, 9 July 2016

Embedded Message Queue (ActiveMQ)

Queue's are an easy way to increase the availability of an application. Using queues, an application can accept input, even though it may not be able to work on it straight away. ActiveMQ is a good java queue, it is also possible to embed activemq within a java application.

Why would you embed a message queue in an application?
If you are after availability and not horizontal scalability then embedding a queue means that your application can continue receiving input even though it may not be able to process it straight away. ActiveMQ supports persistence through Kaha, so the contents of queue's will survive application restart, if your application was to crash before the requests were processed.

Another good reason for embedding a message queue is that the application will be designed with a message queue in mind, therefore if horizontal scalability is required in the future, it will be trivial to run Active MQ outside of the application, and simply change the broker URI to a non embedded ActiveMQ.


To illustrate embedding a queue,  I have created a sample project at https://bitbucket.org/rizvn/embedded-activemq/src

The unit test QueueTest.java shows how the classes can be used.

The basic principle is that an embedded queue can work as a persistent input/output buffer for your application. Below is an example of how the embedded queue can be used to design a system.

Request go on to a queue and are consumed by the application when processing is available. Once processing is complete, responses can be put on a response queues or topics for another client to receive. 

No comments:

Post a Comment