0
我有一个场景,我使用的是Apache Camel(版本2.15.2)来提供允许创建“配置文件”的REST服务。该服务尝试将Profile有效载荷分成多个不同类型的对象(第1,2和3节),并将每个对象类型的创建委托给不同的应用程序。复杂之处有被用来创建第2 & 3.下面是一个例子路由的定义,作为第1,需要的部分创建的数据:骆驼路由响应与我路由中的最后一点不同
rest("/v1/Profile")
.post().consumes("application/json").produces("application/json")
.type(Profile.class)
.description("Create a new profile")
.route()
// Save the original JSON payload into an exchange property
.setProperty(ORIGINAL_PAYLOAD_KEY, simple("${in.body}"))
// validate the payload
.to(postProfileValidationEndpoint)
// Extract Section 1 from the request
.marshal().json(JsonLibrary.Jackson)
.transform().jsonpath("$.section1")
.marshal().json(JsonLibrary.Jackson)
// send the request to Section 1 app
.to(section1Queue)
.unmarshal().json(JsonLibrary.Jackson, Section1.class)
// Save the profile id of the newly created section 1 instance
.setHeader("profileId", new JsonPathExpression("$.profileId"))
// Based on the original payload (see above), extract Section 2 and 3 as separate messages
.split().method("profileSplitter", "generateProfileCreateMessages")
.parallelProcessing()
.choice()
.when(header(SECTION_2_REQUEST))
.to(section2Queue)
.when(header(SECTION_3_REQUEST))
.to(section3Queue)
.end()
// consolidate responses from section 2 and 3 applications
.aggregate(header("breadcrumbId"), profileAggregationStrategy)
.completionTimeout(timeout)
.completionSize(exchangeProperty(COMPLETION_SIZE_PROPERTY))
.to("log:com.example.profile.route?level=DEBUG&showAll=true&multiline=true");
我看到的问题是,日志语句在路线的最后,打印响应体的确切方式,我期望它。但是,当我从PostMan调用这条路由时,返回值是“.unmarshal()。json(JsonLibrary.Jackson,Section1.class)”的结果。
我试过调试和启用跟踪的路线,我还没有找到解释为什么我的聚合结果(我已确认工作正常)不返回。
任何想法?
感谢您的回复。我认为你说的话可能会发生,但是,当我调试路由时,直到我的自定义聚合策略完成后,响应才会返回给客户端。 FWIW,我还分别配置了聚合部分,因此我可以使用自定义聚合策略类以及完成超时和完成大小条件。有没有办法做到这一点,并明确将聚合器绑定到split()的范围? – JJensL