gpt4 book ai didi

java - 如何使用 Apache Camel 聚合器

转载 作者:行者123 更新时间:2023-12-02 13:07:23 24 4
gpt4 key购买 nike

我有一个非常简单的用例,我想将一组字符串放在一起,并尝试使用聚合器 EIP 来实现此目的。然而,当尝试启动路线时,它提示找不到聚合器策略:

java.lang.IllegalArgumentException: AggregationStrategy or AggregationStrategyRef must be set on Aggregate

以下是我重现该问题的方法:

import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class AggregatorTest extends CamelTestSupport {
private static final List<String> LIST = Arrays.asList(new String[] {"one", "two", "three"});
@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.split().body()
.setHeader("cheese", constant("camembert"))
.aggregate(constant("all"))
.to("mock:end");
}
};
}

@Test
public void shouldAggregateStrings() throws Exception {
sendBody("direct:start", LIST);
}
}

当然,解决此问题的一个非常简单的方法是创建聚合策略实现并配置我的路由以使用它。但是我想了解为什么现在设置的方式不起作用。根据here上的camel文档:

By default Camel uses DefaultAggregationCollection and UseLatestAggregationStrategy, so this simple example will just keep the latest received exchange for the given correlation Expression

我还注意到 DefaultAggregationCollection 不再是 Camel 核心的一部分。那么我在这里缺少什么?

最佳答案

那是旧文档。正确的文档位于:http://camel.apache.org/aggregator2

例如,EIP 列表包含指向正确文档的链接:http://camel.apache.org/eip

您可以从这些链接中找到示例,也可以在这个小示例中找到示例:https://github.com/apache/camel/blob/master/examples/camel-example-aggregate/README.md

《Camel in Action》书籍中有一个 EIP 章节,其中还详细介绍了聚合器:http://camel.apache.org/books

关于java - 如何使用 Apache Camel 聚合器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44091590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com