fransvn
fransvn

Reputation: 273

How to handle exceptions from Camel splitter behind remote proxy

I have created a route that via a splitter does multiple lookups, aggregates the responses and returns the list of objects.

I use a remote proxy to invoke the route.

Given that there are multiple branches on the route it is possible that some will succeed and some will fail. How can I get all the returned results but also a list of failures, with reasons for failures, from the remote proxy?

I can think of 3 options, but hope there is something cleaner

  1. Use a header structure that is passed in with remote proxy call to collect errors
  2. Wrap the return value of the remote proxy in structure that contains results and errors
  3. Route errors to some error endpoint (not sure how to correlate with my request though)

Are there any other options?

Upvotes: 0

Views: 112

Answers (2)

Saurabh Nayar
Saurabh Nayar

Reputation: 407

You should be able to get exception details in Aggregation strategy class and accordingly take action.

It depends on what you want to achieve from overall design. As a general practice, if you want consumer of your remote practice to fail on errors, it should get the exception details immediately. If your remote proxy is a REST Endpoint, it can return with 500 error. And similar strategy can be followed for other protocols.

Upvotes: 1

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

I would go with option 3. Route all the errors to a generic error endpoint where you log the errors and return some default response. That way you can refer to that generic error endpoint from all your branches ensuring they will all react the same way whenever they encounter an error.

Upvotes: 1

Related Questions