java - Apache Camel 聚合器输入输出回复

标签 java spring-boot apache-camel

我试图在聚合器完成后得到回复,但出现一个异常,即我没有指定任何聚合器子项,但当我指定 .to() 端点时,我没有收到聚合结果...这可能吗?

Controller :

@SpringBootApplication
@RestController
public class App {
@Produce(uri = "direct:intake")
private ProducerTemplate producerTemplate;

public static void main(final String...args) {
    SpringApplication.run(App.class, args);
}

@RequestMapping("/test/{message}")
public String test(@PathVariable String message) {
    return this.producerTemplate.requestBodyAndHeader("direct:intake", message, "id", "abc123").toString();
}
}

聚合器:

@Component
public class Aggregator extends RouteBuilder {

@Override
public void configure() throws Exception {
    from("direct:intake")
            .aggregate(header("id"))
            .aggregationStrategy(new AggregationStrategy() {
                @Override
                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    if (oldExchange == null)
                        return newExchange;
                    oldExchange.getIn().setBody(oldExchange.getIn().getBody() + "::" + newExchange.getIn().getBody());
                    return oldExchange;
                }
            })
            .completionTimeout(5000)
            .to("stream:out");

}
}

最佳答案

Twitter 上有人好心地告诉我,聚合器完成的交换不会在回复中返回。

关于java - Apache Camel 聚合器输入输出回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45089112/

相关文章:

java - Eclipse 找不到主要方法

java - @AuthenticationPrincipal 与 Spring Boot 不工作

java - 如何管理具有其他相关实体的实体的 API 端点?

rest - 如何在camel Rest中验证JSON请求

java - Camel Hystrix EIP - IgnoreExceptions 以防止调用 Fallback

spring - 带有 Spring DSL + OSGi 的 Karaf 上的 Apache Camel

java - 通过名称获取 JSON 对象值 Java

java - 为什么 System.getProperty ("line.seperator") 返回 null?

java - Spring JPA 复合键 : This class does not define an IdClass

spring - 如何在启动期间终止 Spring 应用程序?