簡體   English   中英

Camel 中是否有任何組件可以運行獨立路由?

[英]Is there any component available in Camel to run standalone route?

我希望子路由從 Timer 路由運行,但以下代碼運行不正常:

兒童路線:

from("direct:processOrder").id("dd")
//  .setBody(constant("select * from customer"))
//  .to("jdbc:testdb")
    .to("sql:select * from EMPLOYEE?dataSource=masterdata")
    .log(LoggingLevel.INFO, "DB")
    .to("log:?level=INFO&showBody=true").end();

主要路線:

from("timer://foo?period=30000")
    .log(LoggingLevel.INFO, "Triggered Company")
    .process(new Processor() {
      public void process(Exchange exchange) throws Exception {
        exchange.getContext().startRoute("dd");
      }
    })
    .end();

輸出:

20/03/05 13:28:07 INFO impl.DefaultCamelContext: StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Route: dd started and consuming from: Endpoint[direct://processOrder]
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Route: route1 started and consuming from: Endpoint[timer://foo?period=30000]
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Total 2 routes, of which 2 is started.
20/03/05 13:28:08 INFO impl.DefaultCamelContext: Apache Camel 2.15.1 (CamelContext: camel-1) started in 0.400 seconds
20/03/05 13:28:09 INFO route1: Triggered Company
20/03/05 13:28:09 INFO impl.DefaultCamelContext: Route: dd started and consuming from: Endpoint[direct://processOrder]

什么組件中使用from孩子的路線,以便它只是運行的時候,我們.startRoute從主路計划?

請參閱直接組件 使用“to”而不是“.process”:

.to("direct:processOrder");

根據您的日志,兩條路由都正確啟動,因此您無需顯式執行.startRoute

要將信號傳遞到另一條路由,請在父路由中調用.to("direct:processOrder")而不是運行您現在擁有的處理器:

from("timer://foo?period=30000")
  .log(LoggingLevel.INFO, "Triggered Company")
  .to("direct:processOrder")
  .end()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM