【Java.Apache.Camel】

來源:互聯網
上載者:User

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();      }  }  



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.