簡體   English   中英

如何使用 Apache Camel 聚合器

[英]How to use Apache Camel aggregator

我有一個非常簡單的用例,我想將一組 sting 放在一起,並嘗試為此使用聚合器 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);
    }
}

當然,解決這個問題的一個非常簡單的方法是創建一個聚合策略實現並配置我的路由來使用它。 但是我想了解為什么現在設置的方式不起作用。 根據這里的駱駝文檔:

默認情況下,Camel 使用 DefaultAggregationCollection 和 UseLatestAggregationStrategy,所以這個簡單的例子將只保留給定相關表達式的最新收到的交換

我還注意到 DefaultAggregationCollection 不再是駱駝核心的一部分。 那么我在這里缺少什么?

那是舊文檔。 正確的文檔位於: 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

我制作了一個小視頻來演示使用 SpringBoot 和 Camel 的這種 EIP 模式。

看看這里: https : //youtu.be/IdGuGGVv51Q

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM