from("stream:in?promptMessage=Enter something: ").to("vm:channel?concurrentConsumers=5"); from("vm:channel?concurrentConsumers=5").to("file://output");Notice that we have to use the full URI, including options in both the producer and consumer. In Camel 2.4 this has been fixed so that only the queue name must match. Using the queue name bar, we could rewrite the previous exmple as follows:
from("direct:foo").to("vm:bar"); from("vm:bar?concurrentConsumers=5").to("file://output");
<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> <choice> <when> <simple>${body} contains 'PHONE'</simple> <to uri="vm:phone" /> </when> <when> <simple>${body} contains 'EMAIL'</simple> <to uri="vm:email" /> </when> <otherwise> <to uri="vm:letter" /> </otherwise> </choice> <!-- and then print to the console --> <to uri="stream:out" /> </route> <route id="phone"> <!-- incoming requests from the servlet is routed --> <from uri="vm:phone" /> <transform> <constant>Phone Karo</constant> </transform> <to uri="stream:out" /> </route> <route id="email"> <!-- incoming requests from the servlet is routed --> <from uri="vm:email" /> <transform> <constant>Send EMAIL</constant> </transform> <to uri="stream:out" /> </route> <route id="letter"> <!-- incoming requests from the servlet is routed --> <from uri="vm:letter" /> <transform> <constant>Post Letter</constant> </transform> <to uri="stream:out" /> </route> </camelContext> </beans>
<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>
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(); } }