rayman rayman - 10 months ago 56
Java Question

Add retry mechanism for bolt on Apache Storm

I have a bolt (dispatcher) in my storm topology which open http request connection.

I want to add retry mechanism in-case of failure (connection time out, fail status, etc..).
The retry should occur only in the dispatcher-bolt and not to start over the whole topology.

usually what I would do is to add a queue which would be responsible for the retry and exception handling (for example after 3 time automatically dispatch the message to an error queue..)

Is it OK to do such thing inside a bolt? anyone has any experience with that and could suggest which library I could use?

Answer Source

Sure! That seems like a reasonable way to handle errors. I'm not sure what library you would need to use except for the one which provides the API for connecting to the queuing system of your choice.

Inside your bolt, you might have code which looks like this:

public void execute(Tuple tuple, BasicOutputCollector collector) {
   try {
      // do something which might fail here...
   } catch (Exception e) {
      // do you want to log the error?
      LOG.error("Bolt error {}", e);
      // do you want the error to show up in storm UI?
      // or just put information on the queue for processing later

As long as you are catching the exception inside your bolt, your topology will not restart.

Another option is to leverage Storm's built-in ability for guaranteed message processing to fail tuples and retry them that way.