Interface SequencedDeadLetterQueue<M extends Message<?>>
- Type Parameters:
M- An implementation ofMessagecontained in thedead letterswithin this queue.
- All Known Implementing Classes:
InMemorySequencedDeadLetterQueue,JdbcSequencedDeadLetterQueue,JpaSequencedDeadLetterQueue,JpaSequencedDeadLetterQueue
The contained sequences are uniquely identifiable through the "sequence identifier." Dead-letters are kept in the
form of a DeadLetter. It is highly recommended to use the process operation (or
any of its variants) to consume letters from the queue for retrying. This method ensure sequences cannot be
concurrently accessed, thus protecting the user against handling messages out of order.
- Since:
- 4.6.0
- Author:
- Steven van Beelen, Allard Buijze, Milan Savic, Mitchell Herrijgers
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of unique sequences contained in this queue.voidclear()Clears out alldead letterspresent in this queue.booleanCheck whether there's a sequence ofdead lettersfor the givensequenceIdentifier.Iterable<Iterable<DeadLetter<? extends M>>> Return alldead lettersequences held by this queue.Iterable<DeadLetter<? extends M>> deadLetterSequence(Object sequenceIdentifier) Return all thedead lettersfor the givensequenceIdentifierin insert order.voidenqueue(Object sequenceIdentifier, DeadLetter<? extends M> letter) Enqueues adead lettercontaining an implementation ofMto this queue.default booleanenqueueIfPresent(Object sequenceIdentifier, Supplier<DeadLetter<? extends M>> letterBuilder) Enqueue the result of the givenletterBuilderonly if there already are otherdead letterswith the samesequenceIdentifierpresent in this queue.voidevict(DeadLetter<? extends M> letter) Evict the givenletterfrom this queue.booleanValidates whether this queue is full for the givensequenceIdentifier.default booleanprocess(Function<DeadLetter<? extends M>, EnqueueDecision<M>> processingTask) Process a sequence of enqueueddead letterswith the givenprocessingTask.booleanprocess(Predicate<DeadLetter<? extends M>> sequenceFilter, Function<DeadLetter<? extends M>, EnqueueDecision<M>> processingTask) Process a sequence of enqueueddead lettersthrough the givenprocessingTaskmatching thesequenceFilter.voidrequeue(DeadLetter<? extends M> letter, UnaryOperator<DeadLetter<? extends M>> 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.
-
Method Details
-
enqueue
void enqueue(@Nonnull Object sequenceIdentifier, @Nonnull DeadLetter<? extends M> letter) throws DeadLetterQueueOverflowException Enqueues 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.- Parameters:
sequenceIdentifier- The identifier of the sequence theletterbelongs to.letter- TheDeadLetterto enqueue.- Throws:
DeadLetterQueueOverflowException- Thrown when this queueis full.
-
enqueueIfPresent
default boolean enqueueIfPresent(@Nonnull Object sequenceIdentifier, @Nonnull Supplier<DeadLetter<? extends M>> letterBuilder) throws DeadLetterQueueOverflowException Enqueue the result of the givenletterBuilderonly if there already are otherdead letterswith the samesequenceIdentifierpresent in this queue.- Parameters:
sequenceIdentifier- The identifier of the sequence to store the result of theletterBuilderin.letterBuilder- TheDeadLetterbuilder constructing the letter to enqueue. Only invoked if the givensequenceIdentifieris contained.- Returns:
- A
trueif there aredead lettersfor the givensequenceIdentifierand thus theletterBuilder'soutcome is inserted. Otherwisefalseis returned. - Throws:
DeadLetterQueueOverflowException- Thrown when this queue isisFull(Object)for the givensequenceIdentifier.
-
evict
Evict the givenletterfrom this queue. Nothing happens if thedead letterdoes not exist in this queue.- Parameters:
letter- Thedead letterto evict from this queue.
-
requeue
void requeue(@Nonnull DeadLetter<? extends M> letter, @Nonnull UnaryOperator<DeadLetter<? extends M>> letterUpdater) throws NoSuchDeadLetterException Reenters 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.- 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
Check whether there's a sequence ofdead lettersfor the givensequenceIdentifier.- Parameters:
sequenceIdentifier- The identifier used to validate for containeddead lettersinstances.- Returns:
trueif there aredead letterspresent for the givensequenceIdentifier,falseotherwise.
-
deadLetterSequence
Return all thedead lettersfor the givensequenceIdentifierin insert order.- Parameters:
sequenceIdentifier- The identifier of the sequence ofdead lettersto return.- Returns:
- All the
dead lettersfor the givensequenceIdentifierin insert order.
-
deadLetters
Iterable<Iterable<DeadLetter<? extends M>>> deadLetters()Return alldead lettersequences held by this queue. The sequences are not necessarily returned in insert order.- Returns:
- All
dead lettersequences held by this queue.
-
isFull
Validates 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.- Parameters:
sequenceIdentifier- The identifier of the sequence to validate for.- Returns:
trueeither when the limit of this queue is reached. Returnsfalseotherwise.
-
size
long size()Returns the number of dead letters contained in this queue.- Returns:
- The number of dead letters contained in this queue.
-
sequenceSize
Returns 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.
- 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
long amountOfSequences()Returns 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.
- Returns:
- The number of unique sequences contained in this queue.
-
process
boolean process(@Nonnull Predicate<DeadLetter<? extends M>> sequenceFilter, @Nonnull Function<DeadLetter<? extends M>, EnqueueDecision<M>> processingTask) Process 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 toevict(DeadLetter)orrequeue(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.- Parameters:
sequenceFilter- Alambdaselecting the sequences within this queue to process with theprocessingTask.processingTask- A function processing adead letter. Returns aEnqueueDecisionused to deduce whether toevict(DeadLetter)orrequeue(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
default boolean process(@Nonnull Function<DeadLetter<? extends M>, EnqueueDecision<M>> processingTask) Process 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 toevict(DeadLetter)orrequeue(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.- Parameters:
processingTask- A function processing adead letter. Returns aEnqueueDecisionused to deduce whether toevict(DeadLetter)orrequeue(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
void clear()Clears out alldead letterspresent in this queue.
-