Nitesh Pratap Singh
Nitesh Pratap Singh

Reputation: 53

Apache camel retry logic while polling from remote server

I am trying to pull files from a remote server and if not able to connect to remote server want to implement below scenarios:

  1. Would like to retry 'N' times,
  2. If the connection is not successful after retrying want to stop polling and throw an exception to consumer saying "Server is not responding"

Upvotes: 0

Views: 720

Answers (2)

user3206236
user3206236

Reputation: 325

I would use a polling strategy for this. So the commit and rollback methods will decide on what to do if there is an issue with the route of some sort

Upvotes: 0

matt helliwell
matt helliwell

Reputation: 2678

In your route you need a bean that connects to the remote server. If it can't connect, it should through an exception.

Then add an onException handler in your route onException(CannotConnectException.class) .maximumRedeliveries(3) .processRef("doSomething")

The "doSomething" process has to take care of stop polling and inform consumer part of the route. For example, to stop polling you could call a method of the connection bean to stop it polling. The best solution is really going to depend on how you rest of your system fits together.

Upvotes: 1

Related Questions