1

有没有办法像这样工作?我说的是什么时候里面的条件。

.choice()
       .when(Exchange::isFailed)
         .to(direct(URI_DEADLETTER))

我试过了:

.when(method(Exchange.class, "isFailed"))
.when().exchange(Exchange::isFailed)

对于第一个解决方案,会引发错误,而第二个解决方案不起作用。我知道我可以从这里创建一个新类和一个方法:如何在骆驼路线中使用 java 布尔条件? 我在这里读到了谓词:http ://www.davsclaus.com/2009/02/apache-camel-and-using-compound.html 。但是如果不使用新的类或谓词,有没有办法可以实现这一点?

4

1 回答 1

3

一个懒惰的解决方案是使用Camel 简单语言http://camel.apache.org/simple.html),它允许您访问当前交换的任何内容(标题、属性、正文、方法等)

.choice()
.when( simple("${exception} != null") )

一个更面向对象的解决方案是使用Camel Predicate (Builder):

Predicate condition1 = ...
Predicate condition2 = ...; 
Predicate isFailed = PredicateBuilder.or(condition1, condition2);   


.choice()
    .when( isFailed )   
于 2018-10-03T16:27:36.170 回答