Class JdbcSequencedDeadLetterQueue<E extends EventMessage<?>>
- Type Parameters:
E- An implementation ofEventMessagecontained in thedead-letterswithin this queue.
- All Implemented Interfaces:
SequencedDeadLetterQueue<E>
SequencedDeadLetterQueue, used for storing dead letters containing
event messages durably. Use the createSchema(DeadLetterTableFactory) operation to build
the table and indices required by this SequencedDeadLetterQueue, providing the desired
DeadLetterTableFactory. The statements used by this queues methods can be
optimized by providing a custom DeadLetterStatementFactory.
Keeps the insertion order intact by saving an incremented index within each unique sequence, backed by the
index property. Each sequence is uniquely identified by the sequence
identifier, stored in the DeadLetterSchema.sequenceIdentifierColumn() sequence identifier} field.
When processing an item, single execution across all applications is guaranteed by setting the
processing started property, locking other processes out of the
sequence for the configured claimDuration (30 seconds by default).
The stored entries are converted to a JdbcDeadLetter when they need to be processed or filtered. In order to
restore the original EventMessage the DeadLetterJdbcConverter is used. The default supports all
EventMessage implementations provided by the framework. If you have a custom variant, you have to build your
own.
upcasters are not supported by this implementation, so
breaking changes for events messages stored in the queue should be avoided.
- Since:
- 4.8.0
- Author:
- Steven van Beelen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classJdbcSequencedDeadLetterQueue.Builder<E extends EventMessage<?>>Builder class to instantiate anJdbcSequencedDeadLetterQueue. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate a JDBC-basedSequencedDeadLetterQueuethrough the givenbuilder. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of unique sequences contained in this queue.static <E extends EventMessage<?>>
JdbcSequencedDeadLetterQueue.Builder<E> builder()Instantiate a builder to construct aJdbcSequencedDeadLetterQueue.voidclear()Clears out alldead letterspresent in this queue.booleanCheck whether there's a sequence ofdead lettersfor the givensequenceIdentifier.voidcreateSchema(DeadLetterTableFactory tableFactory) Performs the DDL queries to create the schema necessary for thisSequencedDeadLetterQueueimplementation.Iterable<Iterable<DeadLetter<? extends E>>> Return alldead lettersequences held by this queue.Iterable<DeadLetter<? extends E>> deadLetterSequence(Object sequenceIdentifier) Return all thedead lettersfor the givensequenceIdentifierin insert order.voidenqueue(Object sequenceIdentifier, DeadLetter<? extends E> letter) Enqueues adead lettercontaining an implementation ofMto this queue.voidevict(DeadLetter<? extends E> letter) Evict the givenletterfrom this queue.booleanValidates whether this queue is full for the givensequenceIdentifier.booleanprocess(Function<DeadLetter<? extends E>, EnqueueDecision<E>> processingTask) Process a sequence of enqueueddead letterswith the givenprocessingTask.booleanprocess(Predicate<DeadLetter<? extends E>> sequenceFilter, Function<DeadLetter<? extends E>, EnqueueDecision<E>> processingTask) Process a sequence of enqueueddead lettersthrough the givenprocessingTaskmatching thesequenceFilter.voidrequeue(DeadLetter<? extends E> letter, UnaryOperator<DeadLetter<? extends E>> letterUpdater) Reenters the givenletter, updating the contents with theletterUpdater.longsequenceSize(Object sequenceIdentifier) Returns the number of dead letters for the sequence matching the givensequenceIdentifiercontained in this queue.longsize()Returns the number of dead letters contained in this queue.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.deadletter.SequencedDeadLetterQueue
enqueueIfPresent
-
Constructor Details
-
JdbcSequencedDeadLetterQueue
Instantiate a JDBC-basedSequencedDeadLetterQueuethrough the givenbuilder.Will validate whether the
processing group,ConnectionProvider,TransactionManager,DeadLetterStatementFactoryandDeadLetterJdbcConverterare set. If for any this is not the case anAxonConfigurationExceptionis thrown.- Parameters:
builder- TheJdbcSequencedDeadLetterQueue.Builderused to instantiate aJdbcSequencedDeadLetterQueueinstance.
-
-
Method Details
-
builder
Instantiate a builder to construct aJdbcSequencedDeadLetterQueue.The following defaults are set by the builder:
- The
table's schemadefaults to aDeadLetterSchema.defaultSchema(). - The
maximum amount of sequencesdefaults to1024. - The
maximum sequence sizedefaults to1024. - The
page sizedefaults to100. - The
claim durationdefaults to 30 seconds.
The
processing group,ConnectionProvider, andTransactionManagerare hard requirements and should be provided.The
JdbcSequencedDeadLetterQueue.Builder.statementFactory(DeadLetterStatementFactory)andJdbcSequencedDeadLetterQueue.Builder.converter(DeadLetterJdbcConverter)are also hard requirements, but users can choose to either set both explicitly or rely on theDefaultDeadLetterStatementFactoryandDefaultDeadLetterJdbcConverterconstructed through thegeneric Serializerandevent Serializer.- Type Parameters:
E- The type ofEventMessagemaintained in thedead letterof thisSequencedDeadLetterQueue.- Returns:
- A Builder that can construct an
JdbcSequencedDeadLetterQueue.
- The
-
createSchema
Performs the DDL queries to create the schema necessary for thisSequencedDeadLetterQueueimplementation.- Parameters:
tableFactory- The factory constructing thePreparedStatementto construct aDeadLetterentry table based on theconfiguredDeadLetterSchema.
-
enqueue
public void enqueue(@Nonnull Object sequenceIdentifier, @Nonnull DeadLetter<? extends E> letter) throws DeadLetterQueueOverflowException Description copied from interface:SequencedDeadLetterQueueEnqueues adead lettercontaining an implementation ofMto this queue.The
dead letterwill be appended to a sequence depending on thesequenceIdentifier. If there is no sequence yet, it will construct one.- Specified by:
enqueuein interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceIdentifier- The identifier of the sequence theletterbelongs to.letter- TheDeadLetterto enqueue.- Throws:
DeadLetterQueueOverflowException- Thrown when this queueis full.
-
evict
Description copied from interface:SequencedDeadLetterQueueEvict the givenletterfrom this queue. Nothing happens if thedead letterdoes not exist in this queue.- Specified by:
evictin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
letter- Thedead letterto evict from this queue.
-
requeue
public void requeue(@Nonnull DeadLetter<? extends E> letter, @Nonnull UnaryOperator<DeadLetter<? extends E>> letterUpdater) throws NoSuchDeadLetterException Description copied from interface:SequencedDeadLetterQueueReenters the givenletter, updating the contents with theletterUpdater. This method should be invoked ifprocessingdecided to keep the letter in the queue.This operation adjusts the
DeadLetter.lastTouched(). It may adjust theDeadLetter.cause()andDeadLetter.diagnostics(), depending on the givenletterUpdater.- Specified by:
requeuein interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
letter- Thedead letterto reenter in this queue.letterUpdater- Alambdataking in the givenletterand updating the entry for requeueing. This may adjust theDeadLetter.cause()andDeadLetter.diagnostics(), for example.- Throws:
NoSuchDeadLetterException- Thrown if the givenletterdoes not exist in the queue.
-
contains
Description copied from interface:SequencedDeadLetterQueueCheck whether there's a sequence ofdead lettersfor the givensequenceIdentifier.- Specified by:
containsin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceIdentifier- The identifier used to validate for containeddead lettersinstances.- Returns:
trueif there aredead letterspresent for the givensequenceIdentifier,falseotherwise.
-
deadLetterSequence
Description copied from interface:SequencedDeadLetterQueueReturn all thedead lettersfor the givensequenceIdentifierin insert order.- Specified by:
deadLetterSequencein interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceIdentifier- The identifier of the sequence ofdead lettersto return.- Returns:
- All the
dead lettersfor the givensequenceIdentifierin insert order.
-
deadLetters
Description copied from interface:SequencedDeadLetterQueueReturn alldead lettersequences held by this queue. The sequences are not necessarily returned in insert order.- Specified by:
deadLettersin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Returns:
- All
dead lettersequences held by this queue.
-
isFull
Description copied from interface:SequencedDeadLetterQueueValidates whether this queue is full for the givensequenceIdentifier.This method returns
trueeither when the maximum amount of sequences or the maximum sequence size is reached.- Specified by:
isFullin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceIdentifier- The identifier of the sequence to validate for.- Returns:
trueeither when the limit of this queue is reached. Returnsfalseotherwise.
-
size
public long size()Description copied from interface:SequencedDeadLetterQueueReturns the number of dead letters contained in this queue.- Specified by:
sizein interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Returns:
- The number of dead letters contained in this queue.
-
sequenceSize
Description copied from interface:SequencedDeadLetterQueueReturns the number of dead letters for the sequence matching the givensequenceIdentifiercontained in this queue.Note that there's a window of opportunity where the size might exceed the maximum sequence size to accompany concurrent usage.
- Specified by:
sequenceSizein interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceIdentifier- The identifier of the sequence to retrieve the size from.- Returns:
- The number of dead letters for the sequence matching the given
sequenceIdentifier.
-
amountOfSequences
public long amountOfSequences()Description copied from interface:SequencedDeadLetterQueueReturns the number of unique sequences contained in this queue.Note that there's a window of opportunity where the size might exceed the maximum amount of sequences to accompany concurrent usage of this dead letter queue.
- Specified by:
amountOfSequencesin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Returns:
- The number of unique sequences contained in this queue.
-
process
public boolean process(@Nonnull Predicate<DeadLetter<? extends E>> sequenceFilter, @Nonnull Function<DeadLetter<? extends E>, EnqueueDecision<E>> processingTask) Description copied from interface:SequencedDeadLetterQueueProcess a sequence of enqueueddead lettersthrough the givenprocessingTaskmatching thesequenceFilter. Will pick the oldest available sequence based on theDeadLetter.lastTouched()field from every sequence's first entry.Note that only a single matching sequence is processed! Furthermore, only the first dead letter is validated, because it is the blocker for the processing of the rest of the sequence.
Uses the
EnqueueDecisionreturned by theprocessingTaskto decide whether toSequencedDeadLetterQueue.evict(DeadLetter)orSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator)a dead letter from the selected sequence. TheprocessingTaskis invoked as long as letters are present in the selected sequence and the result of processing returnsfalseforEnqueueDecision.shouldEnqueue()decision. The latter means the dead letter should be evicted.This operation protects against concurrent invocations of the
processingTaskon the filtered sequence. Doing so ensure enqueued messages are handled in order.- Specified by:
processin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
sequenceFilter- Alambdaselecting the sequences within this queue to process with theprocessingTask.processingTask- A function processing adead letter. Returns aEnqueueDecisionused to deduce whether toSequencedDeadLetterQueue.evict(DeadLetter)orSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator)the dead letter.- Returns:
trueif an entire sequence ofdead letterswas processed successfully,falseotherwise. This means theprocessingTaskprocessed alldead lettersof a sequence and the outcome was to evict each instance.
-
process
public boolean process(@Nonnull Function<DeadLetter<? extends E>, EnqueueDecision<E>> processingTask) Description copied from interface:SequencedDeadLetterQueueProcess a sequence of enqueueddead letterswith the givenprocessingTask. Will pick the oldest available sequence based on theDeadLetter.lastTouched()field from every sequence's first entry.Note that only a single matching sequence is processed!
Uses the
EnqueueDecisionreturned by theprocessingTaskto decide whether toSequencedDeadLetterQueue.evict(DeadLetter)orSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator)the dead letter. TheprocessingTaskis invoked as long as letters are present in the selected sequence and the result of processing returnsfalseforEnqueueDecision.shouldEnqueue()decision. The latter means the dead letter should be evicted.This operation protects against concurrent invocations of the
processingTaskon the filtered sequence. * Doing so ensure enqueued messages are handled in order.- Specified by:
processin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>- Parameters:
processingTask- A function processing adead letter. Returns aEnqueueDecisionused to deduce whether toSequencedDeadLetterQueue.evict(DeadLetter)orSequencedDeadLetterQueue.requeue(DeadLetter, UnaryOperator)the dead letter.- Returns:
trueif an entire sequence ofdead letterswas processed successfully,falseotherwise. This means theprocessingTaskprocessed alldead lettersof a sequence and the outcome was to evict each instance.
-
clear
public void clear()Description copied from interface:SequencedDeadLetterQueueClears out alldead letterspresent in this queue.- Specified by:
clearin interfaceSequencedDeadLetterQueue<E extends EventMessage<?>>
-