Camel ActiveMQ Integration

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Camel being one of the popular trend in the space of Integration, It has very good number of components/connectors across protocols and applications.

ActiveMQ is one of the leading and popular message broker from Apache Foundation. Apart from Camel-JMS component, camel has its dedicated component Camel-ActiveMQ. ( Anyway technically this component is based on JMS component )

Lets create a camel application which takes a file from the file system and sends it to a queue in ActiveMQ broker.

Camel ActiveMQ High level architechture

Camel-ActiveMQ Integration

 

Now lets focus on creating the camel context. Typically the file should be taken from the file system and sent to the queue in ActiveMQ broker. And the routes in the camel-context looks like this.,

<route>
<from uri="file://d:\Input"/>
<to uri="activemq:queue:output"/>
</route>

And anyhow we have to tell where the the activemq is running, which means we have to define the connection factory bean.

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>

Based on the location of ActiveMQ broker, localhost can be replaced with the IP address.

And the complete camel context looks like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://d:\Input"/>
<to uri="activemq:queue:output"/>
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</beans>

How to run this application ?

Lets run this standalone on top of JVM with the help of maven.

These are the activemq dependencies needs to be added in pom.xml ( The complete file can be downloaded from the bottom of this article)

<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.6.0</version>
</dependency>

And that is it, Now just compile the project using mvn compile command and run the application using mvn camel:run 

When the application is up and running, Drop a text file containing some message in D:\Input directory. And notice the ActiveMQ web console which shows the increase in message count for the queue named ‘ output ‘

ActiveMQ web console showing the outpue queue

ActiveMQ web console showing the output queue message count

 

By the way you can use this maven project to run the application instantly.

Click this link to download the zipped version of the code camel-activemq-bushorn

 

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail
Gnanaguru Sattanathan

Gnanaguru Sattanathan

I am a Integration developer and a open source enthusiast. My areas of interest includes Enterprise messaging & SOA. Twitter: @tallguru

You may also like...

9 Responses

  1. Jagan says:

    Nice. But is this your creation or existing one which you made it easy.

  2. Gnanaguru Sattanathan Gnanaguru says:

    Everything already exist ! This is a simple tutorial, Since In open source a simple use case itself takes days.

  3. Senthil Prasad says:

    Guru, Graet start!!!!

  4. Gnanaguru Sattanathan Gnanaguru says:

    Thanks Senthil, Very glad to hear from you.

  5. VRock says:

    Excelent fast tutorial u got it ✔

  6. Panneer says:

    Nice .. Keep going…

  7. Nikita Shah says:

    The download link you mentioned at the bottom of the page ..does not have src files.

  8. Cool. Hope it helped. ! Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>