【问题标题】:Camel: Content based routing, from different fromsCamel:基于内容的路由,来自不同的形式
【发布时间】:2014-11-10 11:35:58
【问题描述】:

我有两个程序,由三个路线组成。

[  
one is a route, from JPA database to bean.  
one is a copier, from file system endpoint to file system endpoint  
]

[  
one is a uploader, from file system endpoint to bean.  
] 

我想根据我的属性文件的输入运行一个程序

<context:property-placeholder location="./run.properties"
    ignore-resource-not-found="false" />

但对于基于内容的路由,我所能找到的只是选择位于 from 下方的示例。例如。

from("direct:start")
    .choice()
        .when(body().contains("Camel"))
            .loadBalance().roundRobin().to("mock:foo").to("mock:bar")
        .otherwise()
            .to("mock:result");

我想要一种重新排列的方法,如下所示:

choice()
   .when(body().contains("Camel"))
      from("direct:start1").loadBalance().roundRobin().to("mock:foo").to("mock:bar")
   .otherwise()
      from("direct:start2").to("mock:result");

【问题讨论】:

  • 你想要什么?你想根据属性开始不同的路线吗?
  • 没错。我想有某种 Spring EL 可以处理这个问题,但我找不到。
  • 如果您使用 Java DSL (camel.apache.org/java-dsl.html),您可以通过编程方式启动路由。简单的方法是读取属性并在路由中写入 if else 语句。
  • 好的,谢谢,这行得通。
  • 如果它有效,请发布您自己的问题答案。

标签: java apache-camel apache-karaf fuseesb


【解决方案1】:

您不需要基于内容的路由来控制是否启动路由...

只需使用autoStartup(boolean) API 来控制...

例如...

from("activemq:queue:special").autoStartup("{{startupRouteProperty}}").to("file://backup");

http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

【讨论】:

  • 我不明白这如何帮助我根据配置文件在两条不同的路线之间进行选择。
  • 你的问题似乎是关于从 CBR 调用子路由,丰富的模式允许......无论如何,我相应地更新了我的答案
  • 谢谢,这看起来是一个可行的解决方案。正如 hutingung 建议的那样,我最终转换为 Java。它没有坏,所以我不会修复它,但下次会试试这个。
【解决方案2】:

我最终这样做的方式:

static ClassPathXmlApplicationContext context;
static CamelContext camel;

...

        context = new ClassPathXmlApplicationContext(
                "META-INF/spring/camel-context.xml");
        camel = new SpringCamelContext(context);

...

    if (property) {
        camel.addRoutes(new RouteBuilder() {
            public void configure() {
                from(..).to(..)
            }
        });
    } else {
        camel.addRoutes(new RouteBuilder() {
            public void configure() {
                from(..).to(..)
            }
        });
    }

    camel.start();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多