【问题标题】:Is there any component available in Camel to run standalone route?Camel 中是否有任何组件可用于运行独立路线?
【发布时间】:2020-03-05 08:02:01
【问题描述】:

我希望子路由从 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 时运行?

【问题讨论】:

    标签: java apache-camel camel-sql camel-jdbc


    【解决方案1】:

    根据您的日志,两条路由均正确启动,因此您无需显式执行.startRoute

    要将信号传递到另一个路由,请在您的父路由中调用.to("direct:processOrder"),而不是运行您现在拥有的处理器:

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

    【讨论】:

      【解决方案2】:

      direct component。使用“to”而不是“.process”:

      .to("direct:processOrder");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多