2
votes

I am interested in using RedeliveryPolicy in Camel to retry redelivery of a message to an endpoint when a certain exception is returned. But I cannot seem to find many examples of how to configure it.

At the moment I am trying:

    from("direct:entry")
            .onException(ResourceNotFoundException.class)
                .redeliveryPolicy(new RedeliveryPolicy().delayPattern("delayPattern=0:" + aocmDelay + ",10:1000;15:2000:19:10000"))
                .handled(true)
            .end()
            .to("direct:destination");

I have the destination endpoint failing with a ResourceNotFoundException but the onException handling is not being called and the redelivery does not take effect. Any ideas of what I am doing wrong?

1

1 Answers

4
votes

You need to set the single properties of a redelivery policy.

from("direct:entry")
    .onException(ResourceNotFoundException.class)
        .maximumRedeliveries(20)
        .delayPattern("1:2000;10:1000;15:2000;19:10000")
        .handled(true)
        .end()
    .to("direct:destination");

Additional comments:

  • you need to define the maximum redelivery attempts (if not defined elsewhere) otherwise the default of zero is used
  • in the delay pattern you had two typos
    delayPattern=0:" + aocmDelay + ",10:1000;15:2000:19:10000
    ________________________________;_______________;________
  • the redelivery count starts with 1, if you define 0:1000;1:5000 the first redelivery is delayed by five seconds not by one