正如这个链接所说的死信通道,我知道消息的标题包含最大重新传递时间。
Starting with 2.6: The header CamelRedeliveryMaxCounter, which is also defined on the Exchange.REDELIVERY_MAX_COUNTER, contains the maximum redelivery setting
所以我尝试设置Exchange.REDELIVERY_MAX_COUNTER
为 6 作为
arg0.getIn().setHeader(Exchange.REDELIVERY_MAX_COUNTER,6);
int max =arg0.getIn().getHeader(Exchange.REDELIVERY_MAX_COUNTER, Integer.class);
System.out.println(max);
这是我的完整代码
public class ActivemqRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:queue:MyQueue")
.onException(IOException.class)
.maximumRedeliveries(2)
.redeliveryDelay(4000)
.handled(true)
.beanRef("msgPro2","SendMail")
.to("activemq:queue:MyQueue.DLQ")
.end()
.transacted()
.process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
arg0.getIn().setHeader(Exchange.REDELIVERY_MAX_COUNTER,6);
int max = arg0.getIn().getHeader(Exchange.REDELIVERY_MAX_COUNTER, Integer.class);
System.out.println(max);
/*error producing code*/
}}
);
由于Processor()
消息中存在错误,因此尝试重新发送 2 次,但我将其重置Exchange.REDELIVERY_MAX_COUNTER
为 6 次,因此假设消息被重新发送 6 次,但它不会发生,而是仅重新发送 2 次。但是我可以在输出中看到 6,因为我打印了max
值。谁能建议我有什么问题?