0

So I have two classes that I can call on redelivery in the Camel Error Handler. I have wrapped the two Processors in a single Processor so I can set the single Processor as the onRedeliveryHandler.

My question is this, if the onRedeliveryHandler sets a state that needs to be cleaned up once the route has finished successfully, what is a good way to do this?

My route is complicated in that there are many different routes the message could end up in the success case. Right now I have each of these routes call a cleanup route that lets the handler know of the success. This works but it seems like there should be a better way as I have two issues with this.

First, if redelivery never entered, I don't need to clean up the onRedelivery state.

Second, I have to manually add a call to the cleanup route from each of my success endpoint routes.

Is there a better / more standard way to do this?

Namphibian
  • 12,046
  • 7
  • 46
  • 76
John B
  • 32,493
  • 6
  • 77
  • 98
  • 1
    Its a bit hard to say without seeing the routes. Are you keeping track of the re-delivery state? Setting it in the header for example? I think you might be able to use the route policy to specify calling the `cleanup` code when ever the routes end. This will probably let you reduce the amount of code you need to add manually to each route. See this answer http://stackoverflow.com/questions/23809040/camel-spring-osgi-is-there-a-way-to-specify-the-stop-method/23817812#23817812 – Namphibian Jul 03 '14 at 01:35
  • Thanks. The RoutePolicy looks great. – John B Jul 03 '14 at 10:41
  • One challenge I have with this is that I only want to clean up if the route exited successfully. However, the `exchangeDone` method is called even if the route exited due to an exception. – John B Jul 03 '14 at 18:15
  • John B as I dont have all the detail I am going to take shot in the dark here but the route policy has a handleException event that is raised. What I would try is to set some header property here so in other words if an exception occurs then add or set a header property stating `errorflag = true` for example. When the route completes I would then check this header property and then do cleanup. Like I said bit hard to give solid advise without all the details. – Namphibian Jul 03 '14 at 22:13

0 Answers0