Class DeadLetteringEventHandlerInvoker.Builder
- Enclosing class:
DeadLetteringEventHandlerInvoker
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 used
defaults to 1024. Providing at least one Event Handler, a SequencedDeadLetterQueue, and a
TransactionManager are hard requirements and as such should be provided.
-
Method Summary
Modifier and TypeMethodDescriptionallowReset(boolean allowReset) Sets whether thisDeadLetteringEventHandlerInvokersupports resets of the providedSequencedDeadLetterQueue.build()Initializes aDeadLetteringEventHandlerInvokeras specified through this Builder.Enabled thisDeadLetteringEventHandlerInvokerto cache sequence identifiers.enqueuePolicy(EnqueuePolicy<EventMessage<?>> enqueuePolicy) Sets theEnqueuePolicythisEventHandlerInvokeruses to decide whether adead lettershould be added to theSequencedDeadLetterQueue.queue(SequencedDeadLetterQueue<EventMessage<?>> queue) Sets theSequencedDeadLetterQueuethisEventHandlerInvokermaintains dead letters with.sequenceIdentifierCacheSize(int sequenceIdentifierCacheSize) Sets the size of the cache.transactionManager(TransactionManager transactionManager) Sets theTransactionManagerused by this invoker for all operations involving the configuredSequencedDeadLetterQueue.protected voidvalidate()Validate whether the fields contained in this Builder are set accordingly.Methods inherited from class org.axonframework.eventhandling.SimpleEventHandlerInvoker.Builder
eventHandlers, eventHandlers, handlerDefinition, listenerInvocationErrorHandler, parameterResolverFactory, sequencingPolicy, wrapEventMessageHandler
-
Method Details
-
queue
public DeadLetteringEventHandlerInvoker.Builder queue(@Nonnull SequencedDeadLetterQueue<EventMessage<?>> queue) Sets theSequencedDeadLetterQueuethisEventHandlerInvokermaintains dead letters with.- Parameters:
queue- TheSequencedDeadLetterQueuethisEventHandlerInvokermaintains dead letters with.- Returns:
- The current Builder instance for fluent interfacing.
-
enqueuePolicy
public DeadLetteringEventHandlerInvoker.Builder enqueuePolicy(EnqueuePolicy<EventMessage<?>> enqueuePolicy) Sets theEnqueuePolicythisEventHandlerInvokeruses to decide whether adead lettershould be added to theSequencedDeadLetterQueue. Defaults to returningDecisions.enqueue(Throwable)that truncates theThrowable.getMessage()size to1024characters when invoked for any dead letter.- Parameters:
enqueuePolicy- TheEnqueuePolicythisEventHandlerInvokeruses to decide whether adead lettershould be added to theSequencedDeadLetterQueue.- Returns:
- The current Builder, for fluent interfacing.
-
transactionManager
public DeadLetteringEventHandlerInvoker.Builder transactionManager(@Nonnull TransactionManager transactionManager) Sets theTransactionManagerused by this invoker for all operations involving the configuredSequencedDeadLetterQueue.- Parameters:
transactionManager- TheTransactionManagerused by this invoker for all operations involving the configuredSequencedDeadLetterQueue- Returns:
- The current Builder instance for fluent interfacing.
-
allowReset
Sets whether thisDeadLetteringEventHandlerInvokersupports resets of the providedSequencedDeadLetterQueue. If set totrue,SequencedDeadLetterQueue.clear()will be invoked upon aSimpleEventHandlerInvoker.performReset()/SimpleEventHandlerInvoker.performReset(Object)invocation. Defaults tofalse.- Parameters:
allowReset- A toggle dictating whether thisDeadLetteringEventHandlerInvokersupports resets of the providedSequencedDeadLetterQueue.- Returns:
- The current Builder instance for fluent interfacing.
-
enableSequenceIdentifierCache
Enabled thisDeadLetteringEventHandlerInvokerto cache sequence identifiers. If enabled, it will create aSequenceIdentifierCacheper segment. The cache prevents callingSequencedDeadLetterQueue.enqueueIfPresent(Object, Supplier)when we can be sure the sequence identifier is not present.This can happen in two cases. Either we start with an empty
SequencedDeadLetterQueue, and we haven't enqueued this identifier yet. Or the queue was not empty at the start. In this case, we can skip the identifier once we checked that we did not enqueue it before. If the identifier might be present, we always call the SequencedDeadLetterQueue#enqueueIfPresent(Object, Supplier)} as the sequence might have been cleaned up in the meantime.- Returns:
- The current Builder instance for fluent interfacing.
-
sequenceIdentifierCacheSize
public DeadLetteringEventHandlerInvoker.Builder sequenceIdentifierCacheSize(int sequenceIdentifierCacheSize) Sets the size of the cache. When there are already sequences stored in a dead-letter queue, we need to check for each sequence identifier if it's already included. This result is stored so we can skip a second "is enqueued" check when we encounter the same sequence identifier. This method thus limits memory use of the cache. The size defaults to1024.If you have a lot of long-living aggregates, it might improve performance to increase the cache size at the cost of more memory use. If you only have aggregates that are short-lived, setting it to a lower value frees up memory, while it might not affect performance.
This setting is applied per
Segment. Note that this setting will only be used in combination withenableSequenceIdentifierCache(), and when theSequencedDeadLetterQueueis not empty when constructing the cache.- Parameters:
sequenceIdentifierCacheSize- The size to keep track of sequence identifiers which are not present.- Returns:
- The current Builder instance for fluent interfacing.
-
build
Initializes aDeadLetteringEventHandlerInvokeras specified through this Builder.- Overrides:
buildin classSimpleEventHandlerInvoker.Builder<DeadLetteringEventHandlerInvoker.Builder>- Returns:
- A
DeadLetteringEventHandlerInvokeras specified through this Builder.
-
validate
protected void validate()Validate whether the fields contained in this Builder are set accordingly.- Overrides:
validatein classSimpleEventHandlerInvoker.Builder<DeadLetteringEventHandlerInvoker.Builder>- Throws:
AxonConfigurationException- When one field asserts to be incorrect according to the Builder's specifications.
-