骆驼路线响应与我的路线中的最后一点不同

时间:2015-10-16 21:41:39

标签: apache-camel integration

我有一个场景,我使用Apache Camel(版本2.15.2)来提供REST服务,该服务允许" Profile"创建。该服务尝试将Profile有效负载拆分为多个不同类型的对象(第1,2和3节),并将每个对象类型的创建委托给不同的应用程序。复杂性是作为第1部分的一部分创建的数据,需要用于创建第2节和第2部分。这是一个示例路由定义:

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)"的结果。

我已尝试调试并在路线上启用跟踪,但我还没有找到解释为什么我的汇总结果(我已经确认按预期工作)不会被返回。< / p>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

聚合的输出在与输入不同的线程中运行。因此,在REST响应发送回客户端之后,日志记录就会发生。

拆分器具有可用于在同一请求中聚合的内置聚合器,因此您可以将其用作REST响应的一部分。

相关问题