RSS

Apache-Camel with Java (Integration)

11 Oct
Apache-Camel with Java (Integration)

Apache camel is very useful routing implementation. If you involve with some integration then you will realize how it is solving your problems. When technology evolves Integration will come to the picture as follows.

A company has a software, which runs in old technology. The company wants to go for another tool, which is going to work on latest platforms and technology. But still the company need to get integrated with the old system because new tool depends on the company data, which is in old system. In this case we need to come up with good solution that can be bridge to the communication. In the industry we used Message Queues to make realtime communication so if it is realtime we can use the message queue in between the two systems.

Above sample is really simple scenario but think about if you have number of systems in downstream to communicate, then you will need proper routing mechanism otherwise you will end up with multiple endpoints, which is doing the same thing (duplicate work). Apache Camel is open source tool for routing data with JAVA application.

Apache Camel

I have created simple adapter with apache camel routes. It explains how to use camel routes in implementation level. This is a maven project produce the war file, which you can deploy on apache tomcat and subscribe to the queue. ( I hope you have understanding of use Spring Boot and Spring Profile) This sample doesn’t contain JMS client to publish messages so I’m going to use the ActiveMQ console.

You can clone the whole project in following location. https://github.com/malalanayake/camel-sample

In code level you need to create the camel route and camel message processor as you wish. See the following rout configuration and sample message processor implementation.

Follow the instruction to deploy and run the adapter.

Start Apache ActiveMQ and create the queue as “sample_queue” then change the application-dev.properties in resource folder. I used spring profile for switch the context so you need to update the default profile as follows in application.properties

Now build the WAR file and deploy the WAR on Apache Tomcat. Then you will see the WAR adapter is going to subscribe to the sample_queue

activemq

Now go to operation and do “Send To“. Now your adapter is going to consume the given message. See the logs in tomcat console.

send

 

 

after_sent

 

console

 

after_consume

The routing mechanism and routing patterns might vary with the problem domain. However the implementation perspective is similar. For example subscribe to message queue and then route the message to endpoints. I hope you got some idea how to use the camel routes.

Enjoy the integration.

Advertisements
 
3 Comments

Posted by on October 11, 2015 in integration, java, spring

 

Tags: , , , ,

3 responses to “Apache-Camel with Java (Integration)

  1. DataMatters

    October 13, 2015 at 4:04 pm

    Not hating on Camel, but I find it to be ‘old tech’ these days. You can do very quick, testable routing setups using Groovy.

     
  2. Piotr

    June 17, 2016 at 12:39 pm

    I tried your solution and I got org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘camelContext’.

     
    • malalanayake

      June 17, 2016 at 12:53 pm

      Hi Piotr,

      Did you change anything on the project or you just try to run as it is ? This is going to happen because of the Spring framework cannot create the instance out of the camel context with given parameters.

      ex/ In your code you have property injection but you did not declare that in property file.

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: