public class DeadLetteringEventHandlerInvoker extends SimpleEventHandlerInvoker implements SequencedDeadLetterProcessor<EventMessage<?>>, MessageHandlerInterceptorSupport<EventMessage<?>>
EventHandlerInvoker
utilizing a SequencedDeadLetterQueue
to enqueue
events
for which handling failed.
Will use an EnqueuePolicy
to deduce whether failed event handling should result in an
enqueue operation
. Subsequent events belonging to an
already contained "sequence identifier", according to the SequencingPolicy
, are also enqueued. This ensures
event ordering is maintained in face of failures.
This dead lettering invoker provides several operations to process
dead letters
it has enqueued. It will ensure the same set of Event Handling Components is invoked
as with regular event handling when processing a dead letter. These methods will try to process an entire sequence of
dead letters. Furthermore, these are exposed through the SequencedDeadLetterProcessor
contract.
Modifier and Type | Class and Description |
---|---|
static class |
DeadLetteringEventHandlerInvoker.Builder
Builder class to instantiate a
DeadLetteringEventHandlerInvoker . |
Modifier | Constructor and Description |
---|---|
protected |
DeadLetteringEventHandlerInvoker(DeadLetteringEventHandlerInvoker.Builder builder)
Instantiate a dead-lettering
EventHandlerInvoker based on the given builder . |
Modifier and Type | Method and Description |
---|---|
static DeadLetteringEventHandlerInvoker.Builder |
builder()
Instantiate a builder to construct a
DeadLetteringEventHandlerInvoker . |
void |
handle(EventMessage<?> message,
Segment segment)
Handle the given
message for the given segment . |
void |
performReset()
Performs any activities that are required to reset the state managed by handlers assigned to this invoker.
|
<R> void |
performReset(R resetContext)
Performs any activities that are required to reset the state managed by handlers assigned to this invoker.
|
boolean |
process(Predicate<DeadLetter<? extends EventMessage<?>>> sequenceFilter)
Process a sequence of
dead letters matching the given sequenceFilter . |
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
Register the given
handlerInterceptor . |
void |
segmentReleased(Segment segment)
This is a way for an event processor to communicate that a segment which was being processed is released.
|
canHandle, canHandleType, eventHandlers, getListenerInvocationErrorHandler, getSequencingPolicy, invokeHandlers, sequenceIdentifier, sequencingPolicyMatchesSegment, supportsReset
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
processAny
protected DeadLetteringEventHandlerInvoker(DeadLetteringEventHandlerInvoker.Builder builder)
EventHandlerInvoker
based on the given builder
. Uses a
SequencedDeadLetterQueue
to maintain and retrieve dead letters from.builder
- The DeadLetteringEventHandlerInvoker.Builder
used to instantiate a DeadLetteringEventHandlerInvoker
instance.public static DeadLetteringEventHandlerInvoker.Builder builder()
DeadLetteringEventHandlerInvoker
.
The EnqueuePolicy
defaults to returning Decisions.enqueue(Throwable)
that truncates the
Throwable.getMessage()
size to 1024
characters when invoked for any dead letter, the
ListenerInvocationErrorHandler
is defaulted to a PropagatingErrorHandler
, the
SequencingPolicy
to a SequentialPerAggregatePolicy
, allowReset
defaults to false
,
sequenceIdentifierCacheEnabled
defaults to false
and sequenceIdentifierCacheSize
defaults to 1024
. Providing at least one Event Handler, a SequencedDeadLetterQueue
, and a
TransactionManager
are hard requirements and as such should be provided.
DeadLetteringEventHandlerInvoker
.public void handle(@Nonnull EventMessage<?> message, @Nonnull Segment segment) throws Exception
EventHandlerInvoker
message
for the given segment
.
Callers are recommended to invoke EventHandlerInvoker.canHandle(EventMessage, Segment)
prior to invocation, but aren't
required to do so. Implementations must ensure to take the given segment into account when processing messages.
handle
in interface EventHandlerInvoker
handle
in class SimpleEventHandlerInvoker
message
- The message to handlesegment
- The segment for which to handle the messageException
- when an exception occurs while handling the messagepublic void performReset()
EventHandlerInvoker
performReset
in interface EventHandlerInvoker
performReset
in class SimpleEventHandlerInvoker
public <R> void performReset(R resetContext)
EventHandlerInvoker
performReset
in interface EventHandlerInvoker
performReset
in class SimpleEventHandlerInvoker
R
- the type of the provided resetContext
resetContext
- a R
used to support the reset operationpublic boolean process(Predicate<DeadLetter<? extends EventMessage<?>>> sequenceFilter)
SequencedDeadLetterProcessor
dead letters
matching the given sequenceFilter
.
Note that only a single matching sequence is processed! Furthermore, the sequenceFilter
is
only invoked for the first letter of a sequence, as the first entry blocks the entire sequence.
process
in interface SequencedDeadLetterProcessor<EventMessage<?>>
sequenceFilter
- A filter for the first dead letter
entries of each sequence.true
if at least one dead letter
was processed successfully, false
otherwise.public Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
MessageHandlerInterceptorSupport
handlerInterceptor
. After registration, the interceptor will be invoked for each
handled Message on the messaging component that it was registered to, prior to invoking the message's handler.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<EventMessage<?>>
interceptor
- The interceptor to registerpublic void segmentReleased(Segment segment)
EventHandlerInvoker
Segment
.segmentReleased
in interface EventHandlerInvoker
segment
- the segment which was released.Copyright © 2010–2024. All rights reserved.