niren
niren

Reputation: 2731

Camel reset REDELIVERY_MAX_COUNTER to 0 or n is not working

As this link says dead-letter-channel I come to know the header of message contains max re delivery times.

Starting with 2.6: The header CamelRedeliveryMaxCounter, which is also defined on the Exchange.REDELIVERY_MAX_COUNTER, contains the maximum redelivery setting

So I try to set Exchange.REDELIVERY_MAX_COUNTER to 6 as

arg0.getIn().setHeader(Exchange.REDELIVERY_MAX_COUNTER,6);
int max =arg0.getIn().getHeader(Exchange.REDELIVERY_MAX_COUNTER, Integer.class);
System.out.println(max);

This is my full code

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*/
                      }}
                    );

Since the error is there in Processor() the message is trying to be redelivered 2 times, but I reset the Exchange.REDELIVERY_MAX_COUNTER to 6 times so the message is suppose to be redelivered 6 times but its not happen instead its redelivered only for 2 times. But I can see 6 in output since I print max value. Can anyone suggest me what would be wrong?

Upvotes: 2

Views: 1216

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55535

The property is a read-only property. You can use retryWhile if you want to do a dynamic way of redelivery number of times.

Upvotes: 3

Related Questions