【发布时间】:2019-02-23 10:09:36
【问题描述】:
我有一条骆驼路线,根据一些 id 进行拆分和聚合。当检索到一个 id 时,将调用另一个端点以根据该 id 检索项目信息。检索项目信息后,我必须通过调用多个丰富的方法来丰富它。在第一个丰富方法中,我必须进行一些 xpath 处理,其中无法检索我将在交换中设置为属性的 primaryOrgId 值,不要担心 xpath 处理,我已经解决了,但我的问题是当我在第一个丰富内设置属性(primaryOrgId)。当路由转到第二个丰富部分时,属性值不会保持不变。当我记录 primaryOrgId 值时,“testValue”的原始值(这是在 direct:createSomeIds 路由中设置的)是显示的,而不是在第一个丰富部分中设置的“changeTheValueHere”。
我正在使用基于 Fuse 6.2.1 的 Camel 2.15。
我去了骆驼网站,从http://camel.apache.org/content-enricher.html 阅读了这部分内容。我不确定我是否理解如何实现......“为此,您必须在 端点 URI" .. 这段文字是在谈论标头,我认为它也适用于交换中的属性。
pollEnrich 或enrich 不会从当前访问任何数据 交换,这意味着在轮询时它不能使用任何现有的 您可能在 Exchange 上设置的标头。例如,您不能设置 Exchange.FILE_NAME 标头中的文件名并使用 pollEnrich 仅使用该文件。为此,您必须在 端点 URI。
这是我的代码:
from("direct:createSomeIds")
.routeId("createSomeIds")
.process(new IdCreatorProcessor()
.setProperty("primaryOrgId").constant("testValue")
.split(xpath("/TempProjects/TempProject/Code/text()").namespaces(ns) , new IdStrategy())
.to("direct:splitRouteById")
.end();
from("direct:splitRouteById")
.routeId("splitRouteById")
.to("direct:getProjectByID")
.to("xquery:template/AllProjectToSingleProject.xq") //xquery template
.convertBodyTo(Project.class)
.enrich("direct:getAdditionalInfo", new ProjectStrategy(ProjectStrategy.AggregatorType.AdditionalInfo))
.enrich("direct:getSecondaryInfo", new ProjectStrategy(ProjectStrategy.AggregatorType.SecondaryInfo))
.end();
from("direct:getAdditionalInfo")
//some xpath stuff here
.setProperty("primaryOrgId").constant("changeTheValueHere")
.end();
from("direct:getSecondaryInfo")
.log("Value of primaryOrgId = " + "${exchangeProperty.primaryOrgId}")
.end();
如果您能提供一些代码示例,那将很有帮助。
【问题讨论】:
标签: apache-camel