My new website on Artificial Intelligence and Machine Learning www.aimlfront.com

Apache Camel Console Example

This is a beginner's example that demonstrates how to get started with Apache Camel with console example.
The example is interactive - it reads input from the console, and then transforms the input to upper case and prints it back to the console.
Below xml is Camel xml configuration using spring integration

Router in Xml Configuration:(applicationContext-camel.xml)
<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>
			<!-- read input from the console using the stream component -->
			<from uri="stream:in?promptMessage=Enter something: " />
			<!-- transform the input to upper case using the simple language -->
			<!--
				you can also use other languages such as groovy, ognl, mvel,
				javascript etc.
			-->
			<transform>
				<simple>${body.toUpperCase()}</simple>
			</transform>
			<!-- and then print to the console -->
			<to uri="stream:out" />
		</route>
	</camelContext>
</beans>

Maven entries for pom.xml:In this example we integrate with the console using the Stream component. For this required camel-stream jar to support cosole example
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
			<version>2.13.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>2.13.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-stream</artifactId>
			<version>2.13.0</version>
		</dependency>


Below is my application execution
package com.javavillage.camel.proj;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	AbstractApplicationContext ctx = 
				new ClassPathXmlApplicationContext("applicationContext-camel.xml");
    	ctx.start();
    	System.out.println("Entered>>>>>");
    	ctx.stop();
    }
}


Apache Camel Console Structure

Apache Camel Console Structure

Execute Apache Camel Console Application:

Execute Apache Camel Console Structure