Class DeadLetteringEventHandlingComponent
- All Implemented Interfaces:
DescribableComponent,MessageHandler,SequencedDeadLetterProcessor<EventMessage>,EventHandler,EventHandlingComponent,ReplayStatusChangedHandler,ResetHandler
EventHandlingComponent decorator that uses a SequencedDeadLetterQueue to enqueue
events for which handling failed.
Uses an EnqueuePolicy to decide whether a failed event should be
enqueued. Subsequent events belonging to an already
enqueued "sequence identifier" are also enqueued to maintain event ordering in the face of failures.
This component provides operations to SequencedDeadLetterProcessor.processAny() dead letters it has enqueued through
the SequencedDeadLetterProcessor contract. It ensures the same delegate EventHandlingComponent is
used when processing dead letters as with regular event handling. Each dead letter is processed in its own
UnitOfWork, providing proper transaction boundaries.
- Since:
- 4.6.0
- Author:
- Steven van Beelen, Mitchell Herrijgers, Mateusz Nowak
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe order for decoratingEventHandlingComponentswith dead-lettering support.Fields inherited from class org.axonframework.messaging.eventhandling.DelegatingEventHandlingComponent
delegate -
Constructor Summary
ConstructorsConstructorDescriptionDeadLetteringEventHandlingComponent(EventHandlingComponent delegate, SequencedDeadLetterQueue<EventMessage> queue, EnqueuePolicy<EventMessage> enqueuePolicy, UnitOfWorkFactory unitOfWorkFactory, boolean allowReset) Instantiate aDeadLetteringEventHandlingComponentwith the givendelegate,queue, customEnqueuePolicy, reset behavior, andunitOfWorkFactory. -
Method Summary
Modifier and TypeMethodDescriptionhandle(EventMessage event, ProcessingContext context) Handles the giveneventwithin the givencontext.handle(ResetContext resetContext, ProcessingContext context) Handles the givenResetContextmessage, performing any necessary reset operations.process(Predicate<DeadLetter<? extends EventMessage>> sequenceFilter) Process a sequence ofdead lettersmatching the givensequenceFilter.Methods inherited from class org.axonframework.messaging.eventhandling.DelegatingEventHandlingComponent
describeTo, handle, sequenceIdentifierFor, supportedEvents, supports, supportsResetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.deadletter.SequencedDeadLetterProcessor
processAny
-
Field Details
-
DECORATION_ORDER
public static final int DECORATION_ORDERThe order for decoratingEventHandlingComponentswith dead-lettering support.This order is applied after interceptors to ensure dead-lettering wraps the fully decorated component.
- See Also:
-
-
Constructor Details
-
DeadLetteringEventHandlingComponent
public DeadLetteringEventHandlingComponent(EventHandlingComponent delegate, SequencedDeadLetterQueue<EventMessage> queue, EnqueuePolicy<EventMessage> enqueuePolicy, UnitOfWorkFactory unitOfWorkFactory, boolean allowReset) Instantiate aDeadLetteringEventHandlingComponentwith the givendelegate,queue, customEnqueuePolicy, reset behavior, andunitOfWorkFactory.- Parameters:
delegate- theEventHandlingComponentto delegate event handling toqueue- theSequencedDeadLetterQueueto store dead letters inenqueuePolicy- theEnqueuePolicyto decide whether a failed event should be dead-letteredunitOfWorkFactory- theUnitOfWorkFactoryto createUnitOfWorkinstances for processing dead lettersallowReset- whether to clear the queue on reset. Iftrue,SequencedDeadLetterQueue.clear(ProcessingContext)will be invoked upon a reset
-
-
Method Details
-
handle
Description copied from interface:EventHandler- Specified by:
handlein interfaceEventHandler- Overrides:
handlein classDelegatingEventHandlingComponent- Parameters:
event- The event to handle.context- The context to the giveneventis handled in.- Returns:
- An
empty streamcontaining nothing.
-
handle
Description copied from interface:ResetHandlerHandles the givenResetContextmessage, performing any necessary reset operations.This method is invoked before the processor begins replaying events. Handlers typically use this opportunity to clean up state that will be rebuilt during replay.
If this method completes exceptionally, the reset operation will be aborted and no replay will occur.
- Specified by:
handlein interfaceResetHandler- Overrides:
handlein classDelegatingEventHandlingComponent- Parameters:
resetContext- The reset context message containing reset information and optional payload.context- The processing context for this operation.- Returns:
- An empty message stream after handling completes successfully.
-
process
public CompletableFuture<Boolean> process(Predicate<DeadLetter<? extends EventMessage>> sequenceFilter) Description copied from interface:SequencedDeadLetterProcessorProcess a sequence ofdead lettersmatching the givensequenceFilter.Note that only a single matching sequence is processed! Furthermore, the
sequenceFilteris only invoked for the first letter of a sequence, as the first entry blocks the entire sequence.Each dead letter is processed in its own processing context (typically a
UnitOfWork), which will have theDeadLetteradded as a resource (viaDeadLetter.RESOURCE_KEY). The message from the dead letter is also added to the context viaMessage.RESOURCE_KEY.- Specified by:
processin interfaceSequencedDeadLetterProcessor<EventMessage>- Parameters:
sequenceFilter- A filter for the firstdead letterentries of each sequence.- Returns:
- a
CompletableFuturewithtrueif at least onedead letterwas processed successfully,falseotherwise
-