如何使用camel recipentList

 巴萨小Q 发布于 2023-01-07 13:08

我只是试图让一个使用RecipentList的骆驼路线工作.但首先是一个问题:两者之间有什么区别

Multicast/RecipentList(两者都没有并行处理)

多个"到"?

在我的情况下,我希望我的一些路线并行处理.目前所有人都使用多个

在for循环中添加"to":

RouteDefinition someRoute = createSomeRout(fromPart, id); \\ method
for (String pcrfTarget : cepConfig.pcrfCepTargets()) {
    log.info("...to " + pcrfTarget);
    someRoute.to(pcrfTarget + "?mode=" + Mode.insertAddId.name());
}

是否有直接的方法来使用recipientList并在最后添加parallelProcessing?我也尝试创建一个简单的例子,但它失败了(书籍和互联网中唯一的例子就是使用/操作标题:-().这是我的例子(错误):

public class Experiments extends CamelTestSupport {
    private static final String MOCK2 = "mock:mock2";
    private static final String MOCK1 = "mock:mock1";
    private static String PCRF_TEST_FILES;

    public Experiments() throws URISyntaxException {
        PCRF_TEST_FILES = ClassLoader.getSystemResource("pcrf-files").toURI().toString();
    }

    @Test
    public void test() throws InterruptedException {
        MockEndpoint mockIn = getMockEndpoint(MOCK1);
        MockEndpoint mockOut = getMockEndpoint(MOCK2);
        mockIn.expectedMessageCount(5);
        mockOut.expectedMessageCount(5);
        // data in mock are available after this call
        assertMockEndpointsSatisfied();
    }

    /*
     * (non-Javadoc)
     *
     * @see org.apache.camel.test.junit4.CamelTestSupport#createRouteBuilder()
     */
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                //from(PCRF_TEST_FILES + "?noop=true").unmarshal().gzip().to(MOCK1).to(MOCK2); //working
                from(PCRF_TEST_FILES + "?noop=true").unmarshal().gzip().recipientList(method(Experiments.class)).parallelProcessing(); //not working
            }
        };
    }

    @RecipientList
    public String[] recipents() {
        return new String[] { MOCK1, MOCK2 };
    }

}

我收到错误:

org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[EDR_UPCC244_MPU842_0370_20140428000008.csv.gz]
...
Caused by: java.lang.AssertionError: expected null, but was:<[B@48d19957>

我认为由于某种原因,camel尝试使用文件内容来获取收件人?!有人可以提供一个示例,如何动态创建recipentList,但不是基于交换附带的数据,而是基于独立数据(在我的情况下在配置中给出).

谢谢

1 个回答
  • 混合@RecipientList并且recipientList()不可能如Camel文档中所述("使用方法调用作为收件人列表"部分).因此,只需使用其中一个.

    1.使用recipientList()

    @RecipientList从方法中删除:

    // No @RecipientList annotation
    public String[] recipents() {
        return new String[] { MOCK1, MOCK2 };
    }
    

    并按如下方式定义路线:

    from("direct:start")
        .recipientList()
        .method(Experiments.class)  // you may define a method name as well if there is more than one
        .parallelProcessing();
    

    要么:

    from("direct:start")
        .recipientList(method(Experiments.class))  // you may define a method name as well if there is more than one
        .parallelProcessing();
    

    2.使用@RecipientList

    @RecipientListbean以下一起使用:

    from("direct:start")
        .bean(Experiments.class);  // you may define a method name as well if there is more than one
    

    要实现并行处理,需要将该parallelProcessing属性添加到@RecipientList注释:

    @RecipientList(parallelProcessing = true)
    public String[] recipents() {
        return new String[] { MOCK1, MOCK2 };
    }
    

    2023-01-07 13:10 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有