【发布时间】:2016-01-15 18:25:52
【问题描述】:
我有一个场景,我使用 Apache Camel(版本 2.15.2)来提供允许创建“配置文件”的 REST 服务。该服务尝试将 Profile 有效负载拆分为多个不同类型的对象(第 1、2 和 3 节),并将每个对象类型的创建委托给不同的应用程序。复杂之处在于,作为第 1 节的一部分创建的数据需要用于创建第 2 节和第 3 节。这是一个示例路线定义:
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)”的结果。
我已经尝试调试并启用对路由的跟踪,但我还没有解释为什么我的聚合结果(我已经确认按预期工作)没有返回。
有什么想法吗?
【问题讨论】: