camel10

如果一个消息并没有发送到目的地,那么我么该做怎样的处理呢?

在camel我们可以使用stopOnException这个特性:

ExecutorService executor = Executors.newFixedThreadPool(16);

from("jms:xmlOrders")

.multicast().stopOnException()

.parallelProcessing().executorService(executor)

.to("jms:accounting", "jms:production");


spring DSL完成上述同样的功能:

<bean id="executor" class="java.util.concurrent.Executors"  factory-method="newFixedThreadPool">

<constructor-arg index="0" value="16"/>

</bean>


<route>

<from uri="jms:xmlOrders"/>

<multicast stopOnException="true" parallelProcessing="true" executorServiceRef="executor">

<to uri="jms:accounting"/>

<to uri="jms:production"/>

</multicast>

</route>


通过 recipientList()方法动态的增加消息队列

from("jms:xmlOrders")

.setHeader("customer", xpath("/order/@customer"))

.process(new Processor() {

public void process(Exchange exchange) throws Exception {

String recipients = "jms:accounting";

String customer =exchange.getIn().getHeader("customer", String.class);

if (customer.equals("honda")) {

recipients += ",jms:production";

}

exchange.getIn().setHeader("recipients", recipients);

}

})

.recipientList(header("recipients"));


Spring DSL实现上述的功能:

<route>

<from uri="jms:xmlOrders" />

<setHeader headerName="customer">

<xpath>/order/@customer</xpath>

</setHeader>

<process ref="calculateRecipients" />

<recipientList>

<header>recipients</header>

</recipientList>

</route> 


使用窃听(wireTap)的方法:

from("jms:incomingOrders")

.wireTap("jms:orderAudit")

.choice()

.when(header("CamelFileName").endsWith(".xml"))

.to("jms:xmlOrders")

.when(header("CamelFileName").regex("^.*(csv|csl)$"))

.to("jms:csvOrders")

.otherwise()

.to("jms:badOrders");

使用窃听的方法.wireTap("jms:orderAudit")能够将exchange的副本发送到jms:orderAudit队列中,并且不会影响路由的过程。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值