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 log4j.properties) - 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 log4j.properties file in the same directory as the script:
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
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:
- ActiveMQ - you will need a local ActiveMQ broker running in order to run the scripts
- Hawt.io - 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.