Cloud & Engineering

A Groovy way to implement a JMS Request Response client using Camel

Posted by Admin on 16 September 2014

tech, camel, groovy, jms

While working for one particular client we were under the particular constraint of not having access to the JMS management console (in this instance the ActiveMQ Console). So when it came time to test out integration workflows we needed a quick and easy way to call the SOAP over JMS services. The Deloitte Platform Engineering folks are well versed in their Groovy scripting and came up with this awesome Groovy script:

I don’t think many people could argue that the above code could be made more compact. We certainly don’t think we could improve its succinctness - but we can certainly attempt to keep it almost as short and pack a lot of (pun intended) Groovy extras. Personally, I am a fan of the Apache Camel, so my immediate thought was what would this script look like with a Camel on it? We would gain the benefits of Camel, one of them being great logging (just add - and also JMS replies and temporary queues are handled by the framework. Add a little, gain a lot.

Adding a Camel

The Groovy script allows you to specify a filepath and a header to send via std input. The Camel route then loads in the file and sends the contents as the body. The header value is added to the message as the SOAPJMS_soapAction.

By adding the following file in the same directory as the script:

  #simple console logger to show the jms replies from jms request-response pattern using camel
  log4j.rootLogger=INFO, out
  # uncomment the following line to turn on Camel debugging
  #turn on DEBUG logging to see jms replies
  # CONSOLE appender
  log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
view hosted with ❤ by GitHub

we get the log output from the script as follows:

To complete the loop we have added the server side which will provide a response:

Some like it Hawt is a web console which plays nice with Apache Camel. I extracted these images from it to show the client Groovy JMS and server Groovy JMS flows.

Hawt Camel Routes

Project Setup

Of course, getting to this point requires a fair bit of setup, you need to ensure you have the following installed along with a JDK:

  • Maven
  • Ivy
  • Groovy
  • ActiveMQ - you will need a local ActiveMQ broker running in order to run the scripts
  • - allows you to view and inspect your Camel routes (and your ActiveMQ queues)

To code and debug Groovy I find IntelliJ Community Editon very helpful, and the IvyIDEA Plugin allows seamless integration with Ivy in order to download the dependencies through the IDE. Just ensure you configure Groovy and Ivy in your global libraries.

I hope this has been a Groovy Camel ride, it gets even hawter with other Camel components. It goes to show that a lot of functionality can be packed into small scripts when you stand on the shoulders of open source giants. I extend my great thanks to the Camel open source crew.

Further Reading:


If you like what you read, join our team as we seek to solve wicked problems within Complex Programs, Process Engineering, Integration, Cloud Platforms, DevOps & more!


Have a look at our opening positions in Deloitte. You can search and see which ones we have in Cloud & Engineering.


Have more enquiries? Reach out to our Talent Team directly and they will be able to support you best.

Leave a comment on this blog: