Re: Retry strategy on the consumer side

121 views
Skip to first unread message

Michael Barker

unread,
Nov 29, 2012, 4:18:31 PM11/29/12
to lmax-di...@googlegroups.com
Personally I'd just catch the Exception inside of the EventHandler an
deal with the retry logic locally:

public void onEvent(ValueEvent event, long sequence, boolean endOfBatch)
{
int attempts = 0;
do
{
try
{
doWork(event);
break;
}
catch (Exception e)
{
e.printStackTrace();
}
}
while (attempts < MAX_ATTEMPTS);
}

Mike.

On Mon, Nov 26, 2012 at 2:22 PM, Domenico Maria Giffone
<domenico...@gmail.com> wrote:
> What is the correct way to implement a retry strategy on the consumer side?
> I would like to be able to reprocess the events that have raised an
> exception depending on whether the exception is transient or not.
>
> Thought to modify the interface ExceptionHandler in this way:
>
> /**
> * Strategy for handling uncaught exceptions when processing an event.
> *
> * If the strategy wishes to suspend further processing by the {@link
> BatchEventProcessor}
> * then is should throw a {@link RuntimeException}.
> * If the strategy wishes to ignore the failed event and to proceed to
> the next
> * then it should return true.
> * If the strategy intends to retry the failed event then it should
> return false.
> *
> * @param ex the exception that propagated from the {@link
> EventHandler}.
> * @param sequence of the event which cause the exception.
> * @param event being processed when the exception occurred.
> *
> * @return true to false, depending on whether you want to proceed to
> the next event
> * or to process again the current event.
> *
> */
> boolean handleAndMoveForward(Throwable ex, long sequence, Object event);
>
> Unfortunately, this involves modifying the catch block of
> BatchExceptionHandler more or less in this way:
>
> ...
>
> catch (final Throwable ex)
> {
> if (exceptionHandler.handleAndMoveForward(ex, nextSequence,
> event))
> {
> sequence.set(nextSequence);
> nextSequence++;
> }
> }
>
> ...
>
> Do you think is the right way? Could you suggest a better solution?
>
> Best Regards,
> Domenico
>
> --
>
>

Michael Barker

unread,
Nov 29, 2012, 4:19:19 PM11/29/12
to lmax-di...@googlegroups.com
Sorry missed a bug:

while(++attempts < MAX_ATTEMPTS);

Domenico Maria Giffone

unread,
Nov 30, 2012, 12:46:28 PM11/30/12
to Disruptor
Well, is much less invasive in this way.
I was so tempted to take advantage of the ExceptionHandler interface
to forget to apply a little pragmatism :-)
Thank you very much.

Domenico
Reply all
Reply to author
Forward
0 new messages