Continuing my adventure with ESB’s and ServiceMix in particular I will describe a simple example of File system and JMS integration.
First of all, we need to do some preparation work to be able to send JMS messages and check if they are delivered/consumed on the JMS message broker. For the purpose of this tutorial I’m going to use Apache ActiveMQ, which by default is provided with ServiceMix.
In this part I’m going to show you how to install ActiveMQ web console for simple monitoring tasks as well as how to build a simple Java application sending XML messages to our JMS message broker.
In the second part of this tutorial I’ll post an example showing how to use ESB to connect JMS and File service units, the application will consume JMS messages and save them to the file system.
So let’s get started.
1. I assume you have downloaded the Fuse ESB and you are able to start it. If not, please have a look into my previouse tutorial under ‘ESB’ category: http://www.softwarepassion.com/apache-servicemix-fuse-esb-with-camel/ , you don’t have to go through the whole tutorial, just read the part about installing and running Fuse ESB instance.
2. First we start with ActiveMQ web console. To install the webconsole you have to execute two commands on the servicemix(fuseesb) console, go to the terminal window where your servicemix is started and type:
TIP: You can find out more about available features by executing:
This should install your activemq webconsole application. Go and check it out at: http://localhost:8181/activemqweb/
3. Now we are going to create simple java application allowing us to send JMS messages to our ActiveMQ instance. Most of this steps are borrowed from the blog post of Ian Christian found here
First, create the simplest maven skeleton by issuing:
Open up the newly created project in eclipse (or any other editor/ide you use) and change the pom.xml file by adding some dependencies:
Once this is ready, we can start coding our Java stuff.
We need just two classes:
public class App
public static String brokerURL = "tcp://localhost:61616";
public static void main( String args ) throws JMSException
// setup the connection to ActiveMQ
ConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL);
Producer producer = new Producer(factory, "test");
public class Producer
private ConnectionFactory factory;
private Connection connection;
private Session session;
private MessageProducer producer;
public Producer(ConnectionFactory factory, String queueName) throws JMSException
this.factory = factory;
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
producer = session.createProducer(destination);
public void run() throws JMSException
for (int i = 0; i < 10; i++)
System.out.println("Creating Message " + i);
Message message = session.createTextMessage(this.mTxt);
public void close() throws JMSException
if (connection != null)
private String mTxt = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<heading>Simple Message</heading>" +
"<body>Check out my Twitter account @grajo</body>" +
Once you build your app with maven you can test it by running the App main method. Make sure that your ServiceMix instance is up and running. On Eclipse you can use the shortcut to run your application (Alt + Shift + X and then J).
Once you run your app the new queue named ‘test’ should be created in your ActiveMQ and 10 XML messages should be visible on that queue.
You can download the eclipse maven based project with the full source code for this example from github at: https://github.com/softberries/activemq_tut
In the next part we will build a ServiceMix application which will listen on the test queue for incoming messages and save them as files onto filesystem.
Leave a Reply
No Releated Posts