在我们的 Java 11 项目中从 Apache Camel 2.x升级到3.7.2后,我们在路由配置类中遇到了一些粗陋的东西,扩展了RouteBuilder
(文档)类。在 Camel 2 中,我使用了 SimpleExpression ${property[" + Exchange.GROUPED_EXCHANGE + "]}
,现在在 Camel 3.x 中已将其重命名为exchangeProperty
(Migration Guide)。到目前为止,一切都很好。
@Override
public void configure() throws Exception {
final SimpleExpression documentAppendix =
new SimpleExpression("${body.appendix}");
final SimpleExpression groupedExchanges =
new SimpleExpression("${exchangeProperty[" + Exchange.GROUPED_EXCHANGE + "]}");
from("direct://input")
.choice()
.when(documentAppendix)
.split(documentAppendix, new GroupedExchangeAggregationStrategy())
.to("direct://input.splitted")
.end()
.setBody(groupedExchanges)
.endChoice()
.otherwise()
.setBody(constant(Lists.newArrayList()))
.end();
// ... omitted
}
运行测试后,一切都失败了,因为正文没有包含预期数量的附录。起初,我们认为可能存在问题,exchangeProperty
但在使用调试器一段时间后,我们发现了以下属性“丢失”的线索:
GroupedExchangeAggregationStrategy
|
v
AbstractListAggregationStrategy
(This class sets the "CamelGroupedExchange" property!)
|
v
AggregateProcessor
doAggregation(...)
ExchangeHelper.preparteAggregation(...)
聚合后的预期返回应该是一个对象列表,可以通过CamelGroupedExchange
or访问,${exchangeProperty[" + Exchange.GROUPED_EXCHANGE + "]}
但它会被newExchange
in覆盖ExchangeHelper.preparteAggregation
。
由于我们没有找到更多证据,有人可以在将 Camel 升级到 3.7.2 后解释这种奇怪的行为吗?也许 ExchangeHelper 和可用的 ExchangePattern/MEP 模式(CAMEL-13286)发生了重大变化,但我们无法解决问题。
谢谢你们的帮助!