【问题标题】:Difference between filter and choice in camel骆驼中过滤器和选择之间的区别
【发布时间】:2018-10-25 05:34:14
【问题描述】:

apache Camel中的filter和choice有什么区别?

    from("direct:a")
        .choice()
            .when(header("foo").isEqualTo("bar"))
                .to("direct:b")
            .when(header("foo").isEqualTo("cheese"))
                .to("direct:c")
            .otherwise()
                .to("direct:d");

【问题讨论】:

标签: jboss apache-camel enterprise-integration


【解决方案1】:

简而言之,过滤器就像一个 java if 语句,例如

if x = 2 {
  ...
}

在骆驼中:

.filter(header("foo").isEqualTo("bar"))
  ...
.end()

而选择就像一个java if ... elseif ... elseif ... else 语句,

if x = 2 {
  ...
} else if x = 3 {
  ...
}

在骆驼中:

.choice()
  .when(header("foo").isEqualTo("bar"))
    ...
  .when(header("foo").isEqualTo("chese"))
    ...
  .otherwise()
    ....
.end()

请注意,otherwisechoice 中是可选的。

【讨论】:

    【解决方案2】:

    此外,Choice 和 filter 执行相同的操作,其中 Filter 有附加属性 Exchange 将表明它是否被过滤。

    1. 选择从 2.0 版本开始提供
    2. 过滤器从 2.5 版开始提供

    【讨论】:

      猜你喜欢
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多