Available on GitHub
Overview
This is just a very small, very simple template project for sending messages to JMS queues.
In my current role we have a lot of different components and systems glued together by ActiveMQ and Camel. When developingintegration testing in this environment – it is often useful to create ad-hoc messages and send them to queues directly. This is usually the case when you need to test a subset of a larger system.
I usually knock up a test app to do this, often replicating this functionality time and time again. So I thought it might be useful to pop this into a simple template project that can be easily reused. It also made sense to ‘mavenise’ and ‘springify’ to make it more easily extensible if you need to plug in other components and features in tests.
Just to reiterate – this is just a starting point for developer style, ad hoc testing to support the development process.
Running the Demo
- Prerequisites
- Running instance of ActiveMQ (local/remote)
- Maven and JDK installed
- Configuring
- Edit application.properties to point to your ActiveMQ instance – specifying broker url and queue name
- Edit ‘StartDemo.java’ to provide the ObjectMessage the endpoint is expecting
- Type ‘maven exec:java’ to run the StartDemo class
application.properties
Looking at the Code
All the Spring configuration is set up in the main application-context.xml
application-context.xml
The ObjectMessages are created in the main StartDemo.java class
StartDemo.java
Communication with the server is abstracted away into a Dispatcher object.
MessageDispatcher.java
And that’s about it really!
Conclusion
As stated at the start – this is just a throwaway project I use as a starting point when I need to write something to send messages to an ActiveMQ Queue/
It’s a compromise between something super simple (like a simple class), and something that lends itself easily to being extended. What can often start off as a simple test can grow into something more complex – and as we have maven and spring all configured at the start – it’s then very easy to add in extra dependencies if you find you need them.