Apache Camel —— 一種Enterprise Integration Patterns的實現; 參考《企業整合模式:設計、構建及部署訊息傳遞解決方案》。
提供訊息路由route:準系統是接受訊息、處理訊息和指派訊息。
通過Java領特定領域語言DSL(基於Camel 提供的java API, 或者Spring設定檔等)來配置路由和處理規則。其核心的思想是從一個from源頭得到資料,通過Processor處理,再發到另一個to目的地。
Camel使用URIs表示不同的訊息傳輸模型。
目前支援的URIs類型:
disruptor://
file://
ftp://
hbase://
hdfs://
http://
ibatis://
jdbc://
jms://
jmx://
jpa://
ldap://
quartz://
rmi://
quickfix://
smtp://
sql:
zookeeper:
spring-redis://
,.etc ... ...
第三方擴充:
activemq://
hibernate://
zeromq://
,.etc ... ...
E.g.
E1: ftp - 檔案系統路由
CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { public void configure() { from("ftp://localhost/inbox?username=yorker&password=123456").to( "file:d:/temp/outbox"); } }); context.start(); boolean loop = true; while (loop) { Thread.sleep(25000); } context.stop();
E2: jms路由
private static String user = ActiveMQConnection.DEFAULT_USER; private static String password = ActiveMQConnection.DEFAULT_PASSWORD; private static String url = ActiveMQConnection.DEFAULT_BROKER_URL; public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); System.out.println(url + " " + user + password); context.addRoutes(new RouteBuilder() { public void configure() { from("file:d:/temp/inbox").to( "jms:queue:TOOL.DEFAULT"); } }); context.start(); boolean loop = true; while (loop) { Thread.sleep(25000); } context.stop(); }
E3: http路由
public class HttpPollWithQuartzCamel { public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { public void configure() { from("quartz://report?cron=10 * * * * ?&stateful=true") .to("http://localhost:8080/prjWeb/test.camelreq") .to("file:d:/temp/outbox?fileName=http.csv"); ); } }); context.start(); boolean loop = true; while (loop) { Thread.sleep(25000); } context.stop(); } }