Templates by BIGtheme NET

Creating Camel routes with Spring

Description :
1) The core framework allows to you “wire” beans together to form applications. This wiring
is done through an XML configuration file.
2) we need are a few Java beans (classes),Spring XML configuration file, and an ApplicationContext.
The ApplicationContext is similar to the CamelContext.
3) This example, we have two routing points,
One is from activemq -> Java bean (MySpringBean)
In MySpringBean.java, we are just appending some text and
Finally sending the message to second routing point that is console.

4) We need to define given two routing points in applicationContext.xml file.

// First routing point
// Second routing point

Source Files :



package com.venkatjavasource.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.spring.SpringCamelContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CamelRoutesWithSpringExample {
	public static void main(String[] args) throws Exception {
		ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);
		try {
			ProducerTemplate template = camelContext.createProducerTemplate();
			template.sendBody("activemq:test.queue", "From Queue >> Hello Camel from active mq");
		} finally {


package com.venkatjavasource.camel;

public class MySpringBean {
	public String appendCamel(String msg) {
		return msg + "nFrom Bean >>> (Test Mesaage From MyBean) Camel";

Demo :
Right click on CamelRoutesWithSpringExample.java class,
select “Run As” -> “Java Application”
Out put :
From Queue >> Hello Camel from active mq
From Bean >>> (Test Mesaage From MyBean) Camel