Annotation Interface SequencingPolicy
The sequencing policy determines how events are processed in relation to each other, controlling whether events should be processed sequentially or in parallel.
This annotation can be applied either directly to event handler methods or to the declaring class. When applied to a class, all event handler methods in that class will inherit the sequencing policy. Method-level annotations take precedence over class-level annotations.
Sequencing Policy Implementation Requirements
Custom sequencing policy implementations must adhere to the following constructor parameter rules:
- First parameter (optional): If the payload type is needed, it must be the first
parameter and must be of type
Class<?>. This will be automatically injected with the event's payload type. - Remaining parameters: All other constructor parameters must be primitives
(int, long, boolean, double, etc.), their wrapper types, or String. These values are provided
as strings in the
parameters()array and will be automatically converted to the appropriate types.
Parameter Matching
The framework matches constructors by counting non-Class parameters. If your constructor has a
Class<?> parameter as the first parameter, it is excluded from the parameter count matching.
The number of strings in parameters() must exactly match the number of non-Class constructor parameters.
Supported Parameter Types
The following types are supported for constructor parameters (excluding the optional Class parameter):
- String
- int, Integer
- long, Long
- boolean, Boolean
- double, Double
- float, Float
- byte, Byte
- short, Short
- char, Character (single character strings only)
Example Usage
// Using MetadataSequencingPolicy with metadata key
@EventHandler
@SequencingPolicy(type = MetadataSequencingPolicy.class, parameters = {"userId"})
public void handle(OrderUpdatedEvent event) { ... }
// Using PropertySequencingPolicy with property name
@EventHandler
@SequencingPolicy(type = PropertySequencingPolicy.class, parameters = {"aggregateId"})
public void handle(OrderCreatedEvent event) { ... }
// Custom policy with payload type and additional parameters
@EventHandler
@SequencingPolicy(type = CustomPolicy.class, parameters = {"10", "true"})
public void handle(OrderEvent event) { ... }
// Example CustomPolicy constructor implementation:
public record CustomPolicy(Class<?> payloadType, int intParam, boolean booleanParam) implements SequencingPolicy {
}
Error Conditions
The following conditions will result in an UnsupportedHandlerException:
- No constructor found matching the parameter count
- Class parameter is not the first parameter in the constructor
- Unsupported parameter type used in constructor
- Invalid parameter value conversion (e.g., non-numeric string for int parameter)
- Since:
- 5.0.0
- Author:
- Mateusz Nowak
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionString[]String parameters to pass to the sequencing policy constructor.Class<? extends SequencingPolicy> The sequencing policy implementation class to use.
-
Element Details
-
type
Class<? extends SequencingPolicy> typeThe sequencing policy implementation class to use.The specified class must implement
SequencingPolicyand follow the constructor parameter requirements described in the class documentation.The framework will attempt to instantiate this class using either:
- A no-argument constructor (when
parameters()is empty) - A constructor matching the parameter count and types (when parameters are provided)
If the constructor requires the event payload type, it must be the first parameter of type
Class<?>and will be automatically injected by the framework.- Returns:
- The sequencing policy class to instantiate.
- Default:
org.axonframework.messaging.eventhandling.sequencing.SequentialPolicy.class
- A no-argument constructor (when
-
parameters
String[] parametersString parameters to pass to the sequencing policy constructor.- Returns:
- String parameters to pass to the sequencing policy constructor.
- Default:
{}
-