Class DeadLetterQueueConfiguration
- All Implemented Interfaces:
DescribableComponent
This class provides a fluent API for configuring the DLQ behavior, including:
- Whether DLQ is enabled
- The
EnqueuePolicyto decide which events to dead-letter - Whether to clear the DLQ on processor reset
- The maximum size of the sequence identifier cache
The configuration supports natural merging when combined with defaults using the
UnaryOperator.andThen() pattern. Each setter only modifies its specific field,
allowing processor-specific configurations to override only selected defaults.
Example usage:
config.deadLetterQueue(dlq -> dlq
.enabled()
.enqueuePolicy((letter, cause) -> Decisions.enqueue(cause))
.clearOnReset(false)
.cacheMaxSize(2048)
)
- Since:
- 5.1.0
- Author:
- Mateusz Nowak
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EnqueuePolicy<EventMessage> The default enqueue policy that always enqueues with a truncated cause message. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newDeadLetterQueueConfigurationwith default settings. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the maximum size of the sequence identifier cache.cacheMaxSize(int cacheMaxSize) Sets the maximum size of the sequence identifier cache used by theCachingSequencedDeadLetterQueue.booleanReturns whether to clear the dead-letter queue on reset.clearOnReset(boolean clearOnReset) Sets whether to clear the dead-letter queue when the processor is reset.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.disabled()Disables dead-letter queue functionality for this processor.enabled()Enables dead-letter queue functionality for this processor.Returns the configuredEnqueuePolicy.enqueuePolicy(EnqueuePolicy<EventMessage> enqueuePolicy) Sets theEnqueuePolicyto use when deciding whether to dead-letter a failed event.factory()Returns theSequencedDeadLetterQueueFactoryused to createSequencedDeadLetterQueueinstances.factory(SequencedDeadLetterQueueFactory factory) Sets theSequencedDeadLetterQueueFactoryused to createSequencedDeadLetterQueueinstances.booleanChecks if the DLQ is enabled.
-
Field Details
-
DEFAULT_ENQUEUE_POLICY
The default enqueue policy that always enqueues with a truncated cause message.
-
-
Constructor Details
-
DeadLetterQueueConfiguration
public DeadLetterQueueConfiguration()Creates a newDeadLetterQueueConfigurationwith default settings.By default:
- DLQ is disabled
- Enqueue policy always enqueues with truncated cause
- Clear on reset is enabled
- Cache max size is
SequenceIdentifierCache.DEFAULT_MAX_SIZE - Factory creates
InMemorySequencedDeadLetterQueueinstances
-
-
Method Details
-
enabled
Enables dead-letter queue functionality for this processor.When enabled, failed events will be stored in a dead-letter queue for later processing. The actual queue implementation is provided by a
ComponentFactoryregistered with the configuration.- Returns:
- This configuration instance for fluent chaining.
- See Also:
-
disabled
Disables dead-letter queue functionality for this processor.This method is useful when DLQ is enabled by default (e.g., via shared defaults) but needs to be disabled for a specific processor.
Example usage:
// Enable DLQ for all processors by default configurer.eventProcessing(ep -> ep.pooledStreaming(ps -> ps .defaults(d -> d.deadLetterQueue(dlq -> dlq.enabled())) // But disable for this specific processor .processor(EventProcessorModule.pooledStreaming("no-dlq-processor") .eventHandlingComponents(...) .customized((cfg, c) -> c.deadLetterQueue(dlq -> dlq.disabled()))) ));- Returns:
- This configuration instance for fluent chaining.
- See Also:
-
enqueuePolicy
Sets theEnqueuePolicyto use when deciding whether to dead-letter a failed event.The policy is invoked for each failed event and can decide whether to enqueue it in the dead-letter queue, and with what diagnostics information.
Defaults to a policy that always enqueues with the cause message truncated to 1024 characters.
- Parameters:
enqueuePolicy- TheEnqueuePolicyto use.- Returns:
- This configuration instance for fluent chaining.
-
clearOnReset
Sets whether to clear the dead-letter queue when the processor is reset.When
true(the default), the dead-letter queue will be cleared when a processor reset is triggered. This ensures that dead-lettered events from before the reset are not processed again.Set to
falseif you want to preserve dead-lettered events across resets.- Parameters:
clearOnReset- Whether to clear the DLQ on reset.- Returns:
- This configuration instance for fluent chaining.
-
cacheMaxSize
Sets the maximum size of the sequence identifier cache used by theCachingSequencedDeadLetterQueue.The cache stores which sequence identifiers are known to be enqueued or not enqueued, avoiding expensive delegate calls. When the cache exceeds this size, oldest entries are evicted using LRU policy.
Setting this to
0disables the caching wrapper entirely — the underlyingSequencedDeadLetterQueuewill be used directly.Defaults to
SequenceIdentifierCache.DEFAULT_MAX_SIZE(1024).- Parameters:
cacheMaxSize- The maximum number of non-enqueued identifiers to cache, or0to disable caching.- Returns:
- This configuration instance for fluent chaining.
-
factory
Sets theSequencedDeadLetterQueueFactoryused to createSequencedDeadLetterQueueinstances.The factory receives a component-scoped processing group identifier that uniquely identifies the dead letter queue within its event processor. A single processor may contain multiple event handling components, each with its own DLQ. The name follows the pattern
"DeadLetterQueue[processorName][componentName]", for example"DeadLetterQueue[myProcessor][myComponent]"for a component named"myComponent"within a processor named"myProcessor".This allows using different DLQ implementations such as JPA or JDBC-backed queues instead of the default in-memory implementation.
Defaults to a factory that creates
InMemorySequencedDeadLetterQueueinstances.- Parameters:
factory- TheSequencedDeadLetterQueueFactorythat creates aSequencedDeadLetterQueuefor a given processing group, e.g."DeadLetterQueue[myProcessor][0]".- Returns:
- This configuration instance for fluent chaining.
-
enqueuePolicy
Returns the configuredEnqueuePolicy.- Returns:
- The enqueue policy.
-
clearOnReset
public boolean clearOnReset()Returns whether to clear the dead-letter queue on reset.- Returns:
trueif the queue should be cleared on reset,falseotherwise.
-
cacheMaxSize
public int cacheMaxSize()Returns the maximum size of the sequence identifier cache.- Returns:
- The cache max size.
-
factory
Returns theSequencedDeadLetterQueueFactoryused to createSequencedDeadLetterQueueinstances.- Returns:
- The
SequencedDeadLetterQueueFactory.
-
isEnabled
public boolean isEnabled()Checks if the DLQ is enabled.- Returns:
trueif DLQ is enabled,falseotherwise.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-