Camel将REDELIVERY_MAX_COUNTER重置为0或n无效

时间:2013-10-10 15:44:47

标签: java activemq apache-camel

正如此链接所说dead-letter-channel我知道邮件的标题包含最多交付时间。

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次。但是因为我打印max值,所以我可以在输出中看到6。任何人都可以建议我会出错吗?

1 个答案:

答案 0 :(得分:2)

该属性是只读属性。如果您想要以动态的方式重新传递次数,可以使用retryWhile。