ApacheCamel:pollEnrich不调用动态URI
创始人
2024-09-05 15:00:37
0

如果使用的URI是动态的,使用pollEnrich会出现以下问题:

  1. pollEnrich只使用初始URI进行轮询,而不使用替换的动态URI
  2. pollEnrich返回的Exchange不包含任何消息

为了解决这个问题,可以使用Recipient List EIP来代替pollEnrich。

Recipient List EIP可以动态选择要发送消息的路由,并将任何响应合并回原始Exchange。

以下是使用Recipient List EIP替换pollEnrich的示例代码:

from("direct:start") .recipientList().method(MyDynamicRecipientList.class) .parallelProcessing() .setHeader("originalMessage", simple("${body}")) .aggregate(new MyAggregationStrategy()) .completionSize(2) .completionTimeout(1000) .log("${header.originalMessage} + ' enriched with ' + ${body}") .to("direct:end");

public class MyDynamicRecipientList { public List getRecipients(@Header("myHeader") String myHeaderValue) { // Compute a dynamic URI based on the value of myHeader String dynamicURI = "ftp://myserver/" + myHeaderValue;

// Return a List containing the dynamic URI
return Collections.singletonList(dynamicURI);

} }

public class MyAggregationStrategy implements AggregationStrategy { public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { // Merge the new message into the original message String enrichedMessage = oldExchange.getIn().getBody(String.class) + " + " + newExchange.getIn().getBody(String.class);

// Set the new message as the body of the original Exchange
oldExchange.getIn().setBody(enrichedMessage);

return oldExchange;

} }

相关内容

热门资讯

交流学习经验!Wepoke是真... 交流学习经验!Wepoke是真的(wePoKe)外挂透明挂辅助插件(透视)安装教程(有挂规律)-哔哩...
必看攻略(新Wepoke)外挂... 必看攻略(新Wepoke)外挂透明挂辅助工具(辅助挂)软件透明挂(有挂分析)-哔哩哔哩;新Wepok...
必备科技(德扑ai代理)外挂透... 此外,数据分析德州(德扑ai代理)辅助神器app还具备辅助透视行为开挂功能,通过对客户德扑ai代理透...
热门推荐!wEPOKE(Wep... 1、热门推荐!wEPOKE(WepoKe)外挂透明挂辅助APP(辅助挂)总结教程(有挂工具)-哔哩哔...
一分钟了解(WPK打法)外挂透... 1、一分钟了解(WPK打法)外挂透明挂辅助脚本(透视)德州ai机器人(有挂解密)-哔哩哔哩;详细教程...
技巧知识分享!扑克之城(wEp... 技巧知识分享!扑克之城(wEpOke)外挂透明挂辅助挂(辅助挂)高科技教程(有挂技术)-哔哩哔哩;(...
避坑细节(Wepoke辅助器)... 避坑细节(Wepoke辅助器)外挂透明挂辅助工具(透视)辅助透视(有挂秘籍)-哔哩哔哩;玩家在Wep...
一分钟快速了解(wpk逻辑)外... 一分钟快速了解(wpk逻辑)外挂透明挂辅助挂(透视)的确真的有挂(2022已更新)(哔哩哔哩);最新...
透明规律!wepoke智能ai... 透明规律!wepoke智能ai(wePokE)外挂透明挂辅助器(透视)插件教程(讲解有挂)-哔哩哔哩...
一分钟了解(德州poker)外... 一分钟了解(德州poker)外挂透明挂辅助神器(辅助挂)发牌规律(有挂教程)-哔哩哔哩;德州poke...