package camelinaction; import javax.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.impl.DefaultCamelContext; /** * A route that polls an FTP server for new orders, downloads them, converts the order * file into a JMS Message and then sends it to the JMS incomingOrders queue hosted * on an embedded ActiveMQ broker instance. */ public class FtpToJMSWithProcessorExample { public static void main(String args[]) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); // connect to embedded ActiveMQ JMS broker ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); // add our route to the CamelContext context.addRoutes(new RouteBuilder() { @Override public void configure() { from("ftp://rider.com/orders?username=rider&password=secret"). process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("We just downloaded: " + exchange.getIn().getHeader("CamelFileName")); } }). to("jms:incomingOrders"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); } }