Retry limit for event processing

Hi,

I’d like to limit the number of times that an EventProcessor will attempt to retry an event. My initial thought was to use the metadata on the event message to track the number of times it had been retried and have an ErrorHandler that would increment the value and signal when the event should be abandoned. This was a non-starter however, as I can’t return the modified event message from the ErrorHandler. Another possibility was to have a custom EventProcessor that would track the number of retries and stop processing when the limit was reached. This didn’t seem like an ideal solution though as it would involve a copy-and-paste of the ‘run’ and ‘processNextEntry’ methods from the original to implement the extra logic.

I’m not overly familiar with the architecture yet and feel like I’m probably missing an easy solution somewhere. Any suggestions?

Thanks,
Paul

Hi Paul,

I recently had a discussion about this with someone. A component that does this will be added in Axon 2.1. But building your own isn't too hard.

What you could do, is to put a WeakHashMap in your ErrorHandler (wrap it with Collections.synchronizedMap() for thread safety). In the map, store the EventMessage as key, and an object containing information about past failures, or just a counter, as value. Since the same EventMessage instance is always used, a weak hashmap will automatically clean itself up.

Cheers,

Allard

Hi Allard,

thanks for the prompt reply. The part I’d been uncertain about was how to ensure the ErrorHandler cleaned up after itself. Hadn’t thought about using a WeakHashMap. Is this the planned implementation for Axon 2.1?

Cheers,
Paul

Hi Paul,

for Axon 2.1, I am thinking of providing a context of some sort to the error handler. That way, the error handler has insight in any past attempts. Not sure how that's best incorporated.
If that doesn't turn out to make things a lot easier, my suggested implementation will be part of 2.1.

Cheers,

Allard