如果一个消息并没有发送到目的地,那么我么该做怎样的处理呢?
在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队列中,并且不会影响路由的过程。