【发布时间】:2021-09-20 14:54:08
【问题描述】:
在我们的 Java 11 项目中从 Apache Camel 2.x 升级到 3.7.2 后,我们在路由配置类中遇到了一些粗鲁的问题,扩展了 RouteBuilder @ 987654321@班级。在 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 或${exchangeProperty[" + Exchange.GROUPED_EXCHANGE + "]} 访问,但它会被ExchangeHelper.preparteAggregation 中的newExchange 覆盖。
由于我们没有找到更多证据,在将 Camel 升级到 3.7.2 后,有人可以解释这种奇怪的行为吗?也许 ExchangeHelper 和可用的 ExchangePattern/MEP 模式 (CAMEL-13286) 发生了重大变化,但我们无法解决问题。
感谢你们的帮助!
【问题讨论】:
标签: java maven apache-camel camel-cxf