Interface SequencingPolicy<M extends Message>
- Type Parameters:
M- the type of message to sequence
- All Known Implementing Classes:
ExtractionSequencingPolicy,FallbackSequencingPolicy,FullConcurrencyPolicy,HierarchicalSequencingPolicy,MetadataSequencingPolicy,NoOpSequencingPolicy,PropertySequencingPolicy,RoutingKeySequencingPolicy,SequentialPerAggregatePolicy,SequentialPolicy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Interface to a policy definition for concurrent message processing.
Some implementations are provided by default:
SequentialPolicy: Requires that all messages are handled in the order they arrive. For event handling this also means that at most 1 thread is processing messages for this processor at any time.FullConcurrencyPolicy: Allows each message to be handled independently of any other message. Message processing will typically start in the same order the messages were scheduled in, although no guarantees can be given about the actual processing order.SequentialPerAggregatePolicy: Default event processing policy. Will force events (only supports event handling tasks) generated by the same aggregate to be handled sequentially. At most one thread will be processing events of a single aggregate at any time.RoutingKeySequencingPolicy: Default command processing policy. Will force commands (only supports command handling tasks) routed for the same routing key to be handled sequentially.ExtractionSequencingPolicy: Message processing policy that allows to extract the sequence identifier from the message payload.MetadataSequencingPolicy: Message processing policy that allows to extract the sequence identifier from the message metadata.PropertySequencingPolicy: Message processing policy that extracts the sequence identifier from the message payload based on a given propertyFallbackSequencingPolicy: Message processing policy that allows two policies in an exception-based fallback behavior for sequence identifier extraction.HierarchicalSequencingPolicy: Message processing policy that allows to combine two policies in a fallback pattern (similar toFallbackSequencingPolicy, but not exception based).
- Since:
- 0.3
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptionsequenceIdentifierFor(M message, @Nullable ProcessingContext context) Returns the sequence identifier for the givenmessage.
-
Method Details
-
sequenceIdentifierFor
Returns the sequence identifier for the givenmessage. When two messages have the same identifier (as defined by their equals method), they will be executed sequentially. AOptional#empty()value indicates that there are no sequencing requirements for the handling of this message.The
Optional#empty()should only be returned when the policy cannot determine a sequence identifier for the given message. This typically happens when the policy is not applicable for the specific message type. WhenOptional#empty()is returned, it is up to the component using this policy to provide a default behavior, use another policy, throw an exception or react in any other way - as appropriate.- Parameters:
message- the message for which to get the sequencing identifier.context- the processing context in which the message is being handled. There might be limitations to the instance of theProcessingContextdepending on where theSequencingPolicyis being applied. When handling Events for example, theProcessingContextdoesn't allow you to register phases actions by for exampleProcessingLifecycle.on(org.axonframework.messaging.core.unitofwork.ProcessingLifecycle.Phase, java.util.function.Function<org.axonframework.messaging.core.unitofwork.ProcessingContext, java.util.concurrent.CompletableFuture<?>>)or retrieving components byApplicationContext.component(java.lang.Class<C>).- Returns:
- a sequence identifier for the given message, or
Optional#empty()if this policy cannot determine a sequence identifier for the given message.
-