简体   繁体   中英

Apache Camel: modify endpoint on redelivery

I have a dynamic endpoint with .recipientList(), and I want to change the endpoint in case of an exception. Here is my example:

onException(IOException.class)
 .maximumRedeliveries(2)
 .onRedelivery(urlChangeProcessor)
 .process(failureProccessor);

from("direct:foo")
 .recipientList(simple("cxf:${exchangeProperty.targetUrl}?dataFormat=POJO"));

On exception before the redelivery the "urlChangeProcessor" updates the "targetUrl" property with the correct URL, but the redelivery attempt is still made to the wrong URL.

Is it not possible to change the target endpoint on redelivery? If not, what is an elegant solution? My current workaround is a doTry/doCatch, changing the property in the doCatch and sending it to the same endpoint again.

I use camel 2.15.3

Thanks in advance!

As this is not possible, the solution in my case is to remove the onException and add a doTry/doCatch :

from("direct:foo")
 .doTry()
  .to("direct:out")
 .doCatch(IOException.class)
  .process(urlChangeProcessor)
  .to("direct:foo")
 .end();

from("direct:out")
 .recipientList(simple("cxf:${exchangeProperty.targetUrl}?dataFormat=POJO"));

Add some conditions so this does not end in an endless loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM