标签:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>2.17.0</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-stream</artifactId> <version>2.17.0</version> </dependency> </dependencies>
/** * Hello world! */ public class App { public static void main(String[] args) throws Exception { CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext. context.addRoutes(new RouteBuilder() { public void configure() { from("timer://foo?fixedRate=true&period=1000"). process(new Processor() { public void process(Exchange exchange) throws Exception { exchange.getOut().setBody(new Date()); } }).to("stream:out"); // 2. 为路由配置组件或终端节点. } }); // 3. 添加路由到CamelContext context.setTracing(true); context.start(); // 4. 启动CamelContext. Thread.sleep(Integer.MAX_VALUE); // 为了保持CamelContext处于工作状态,这里需要sleep主线程 context.stop(); // 最后停止CamelContext } }
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>2.17.0</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>2.17.0</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-stream</artifactId> <version>2.17.0</version> </dependency> </dependencies>
<?xml version="1.0" encoding="UTF-8"?> <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"> <bean id="myProcess" class="com.stepnetwork.test.MyProcossor"></bean> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="timer://foo?fixedRate=true&period=1000" /> <process ref="myProcess"></process> <to uri="stream:out" /> </route> </camelContext> </beans>
/** * Created by sam on 5/9/16. */ public class MyProcossor implements Processor { public void process(Exchange exchange) throws Exception { exchange.getOut().setBody(new Date().toString()); } }
/** * Created by sam on 5/10/16. */ public class App2 { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml"); context.start(); System.in.read(); } }
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Tue May 10 15:23:34 CST 2016 Tue May 10 15:23:35 CST 2016 Process finished with exit code 130
Apache Camel系列(2)----Hello World
标签:
原文地址:http://www.cnblogs.com/zengbiaobiao2016/p/5481008.html