【问题标题】:Camel route is activated from java - how to get the response from the last route从java激活骆驼路线 - 如何从最后一条路线获取响应
【发布时间】:2016-09-15 20:05:52
【问题描述】:

从我使用骆驼的弹簧靴中,我想知道是否有可能在骆驼路线完成时获得响应(我的示例中的最后一条路线)。它开始像这样使用 ProducerTemplate:

@Component
public class CamelSender {

@Produce(uri = "direct:start")
private ProducerTemplate template;

public void callRoute(List<String> list) throws ExecutionException, InterruptedException {
    template.sendBodyAndHeader("direct:start", list, "orderId", "123456677"
    );
}
}

//骆驼路线

from("direct:start")
    .log("Split -> Process order ${body}")
    .split().body().to("direct:actionQueue") 
    .end();

 from("direct:actionQueue")
    .bean(ValidateOrders.class)
    .log("Sending to join queue")
    .to("direct:joinQueue");

 from("direct:joinQueue").aggregate(new MyOrderAggregationStrategy())
    .header("orderId")
    .completionTimeout(1000L)
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
                    List<String> orders =   (  (List<String>)  exchange.getIn().getBody());
                    String collect = orders.stream().map(order -> order.toString()).collect(Collectors.joining(","));
                    exchange.getIn().setBody( "Collected validations: "+collect);
                }
            })
            .log("${body}");

如何将带有收集到的验证(字符串)的主体返回给我的 java bean?

【问题讨论】:

    标签: spring-boot apache-camel


    【解决方案1】:

    使用复合消息处理器 EIP 而不是拆分 + 聚合。因为后者是两个独立的进程,聚合器的输出不能作为响应发送回拆分器。前者可以通过使用拆分器中的内置聚合策略来做到这一点。

    您可以找到有关 Camel EIP 的示例和更多详细信息 - 请参阅 仅限拆分器 示例: http://camel.apache.org/composed-message-processor.html

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 2018-09-05
      • 2016-01-15
      • 2020-05-13
      • 2017-05-31
      • 2017-08-04
      • 2020-09-17
      • 1970-01-01
      • 2015-12-21
      相关资源
      最近更新 更多