Class DeadLetteringEventHandlingComponent
- All Implemented Interfaces:
SequencedDeadLetterProcessor<EventMessage>,DescribableComponent,MessageHandler,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.
Replayed events are treated differently when their sequence already holds dead letters. Replayed events positioned before the head of the sequence are handled by the delegate, since they may rebuild state the head letter depends on. Replayed events already present in the sequence are skipped, and a replayed event that fails is enqueued in position order instead of at the tail. Placing letters in position order touches every later letter of the sequence, so it is strongly recommended to resolve enqueued dead letters, by processing or evicting them, before replaying.
This component provides operations to 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.process(Predicate<DeadLetter<? extends EventMessage>> sequenceFilter, @Nullable ProcessingContext context) Process a sequence ofdead lettersmatching the givensequenceFilter.Process any sequence ofdead lettersbelonging to this component.processAny(@Nullable ProcessingContext context) Process any sequence ofdead lettersbelonging to this component in the givencontext.Methods inherited from class org.axonframework.messaging.eventhandling.DelegatingEventHandlingComponent
describeTo, handle, sequenceIdentifierFor, supportedEvents, supports, supportsReset, unwrap
-
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 interfaceEventHandlingComponent- 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
-
process
public CompletableFuture<Boolean> process(Predicate<DeadLetter<? extends EventMessage>> sequenceFilter, @Nullable ProcessingContext context) Description copied from interface:SequencedDeadLetterProcessorProcess a sequence ofdead lettersmatching the givensequenceFilter.The
contextcan be provided optionally to support effective resource management down stream in theSequencedDeadLetterQueueand dead-letter processing task.- Specified by:
processin interfaceSequencedDeadLetterProcessor<EventMessage>- Parameters:
sequenceFilter- a filter for the firstdead letterentries of each sequencecontext- the processing context in which to process the dead letters, if any- Returns:
- a
CompletableFuturewithtrueif at least onedead letterwas processed successfully,falseotherwise
-
processAny
Description copied from interface:SequencedDeadLetterProcessorProcess any sequence ofdead lettersbelonging to this component.Note that only a single matching sequence is processed!
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:
processAnyin interfaceSequencedDeadLetterProcessor<EventMessage>- Returns:
- a
CompletableFuturewithtrueif at least onedead letterwas processed successfully,falseotherwise
-
processAny
Description copied from interface:SequencedDeadLetterProcessorProcess any sequence ofdead lettersbelonging to this component in the givencontext.The
contextcan be provided optionally to support effective resource management down stream in theSequencedDeadLetterQueueand dead-letter processing task.- Specified by:
processAnyin interfaceSequencedDeadLetterProcessor<EventMessage>- Parameters:
context- the processing context in which to process the dead letters, if any- Returns:
- a
CompletableFuturewithtrueif at least onedead letterwas processed successfully,falseotherwise
-