Class AnnotationRoutingStrategy
java.lang.Object
org.axonframework.commandhandling.distributed.AbstractRoutingStrategy
org.axonframework.commandhandling.distributed.AnnotationRoutingStrategy
- All Implemented Interfaces:
RoutingStrategy
RoutingStrategy that expects an
RoutingKey (meta-)annotation on the command message's payload. Commands are
routed based on an identifier annotated with the RoutingKey. This approach ensures that commands with the
same identifier, thus dealt with by the same target, are dispatched to the same node in a distributed Command Bus
(e.g. AxonServerCommandBus or DistributedCommandBus).
An example would be the TargetAggregateIdentifier annotation, which is meta-annotated with
RoutingKey. See the AnnotationCommandTargetResolver for more details on this approach.
This class requires the returned routing keys to implement a proper Object.toString() method. An inconsistent
toString() method may result in different members using different routing keys for the same identifier.
- Since:
- 2.0
- Author:
- Allard Buijze
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aAnnotationRoutingStrategy. -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.AnnotationRoutingStrategy(Class<? extends Annotation> annotationType) Deprecated.in favor of thebuilder()AnnotationRoutingStrategy(Class<? extends Annotation> annotationType, UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy) Deprecated.in favor of thebuilder()protectedInstantiate aAnnotationRoutingStrategybased on the fields contained in the givenbuilder.AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy) Deprecated.in favor of thebuilder() -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Instantiate a Builder to be able to create aAnnotationRoutingStrategy.static AnnotationRoutingStrategyInstantiate a defaultAnnotationRoutingStrategy.protected StringdoResolveRoutingKey(CommandMessage<?> command) Resolve the Routing Key for the givencommand.Methods inherited from class org.axonframework.commandhandling.distributed.AbstractRoutingStrategy
getRoutingKey
-
Constructor Details
-
AnnotationRoutingStrategy
Instantiate aAnnotationRoutingStrategybased on the fields contained in the givenbuilder.- Parameters:
builder- theAnnotationRoutingStrategy.Builderused to instantiate aAnnotationRoutingStrategyinstance
-
AnnotationRoutingStrategy
Deprecated.in favor of thebuilder()Initializes a Routing Strategy that fails when an incoming command does not define a field as theRoutingKeyto base the routing on. -
AnnotationRoutingStrategy
Deprecated.in favor of thebuilder()Initializes a Routing Strategy that uses the given annotation to resolve the targeted identifier.- Parameters:
annotationType- the type of annotation marking the field or method providing the identifier of the targeted model
-
AnnotationRoutingStrategy
Deprecated.in favor of thebuilder()Initializes a Routing Strategy that uses the givenunresolvedRoutingKeyPolicywhen an incoming command does not define aRoutingKeyannotated field to base the routing on.- Parameters:
unresolvedRoutingKeyPolicy- aUnresolvedRoutingKeyPolicyindicating what should be done when a Command does not contain information about the routing key to use
-
AnnotationRoutingStrategy
@Deprecated public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType, UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy) Deprecated.in favor of thebuilder()Initializes a Routing Strategy that uses the given annotation to resolve the targeted identifier and the givenunresolvedRoutingKeyPolicywhen an incoming command does not define an Identifier to base the routing key on.- Parameters:
annotationType- the type of annotation marking the field or method providing the identifier of the targeted modelunresolvedRoutingKeyPolicy- aUnresolvedRoutingKeyPolicyindicating what should be done when a Command does not contain information about the routing key to use
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aAnnotationRoutingStrategy.The
annotationTypeis defaulted toRoutingKeyand thefallbackRoutingStrategytoUnresolvedRoutingKeyPolicy.RANDOM_KEY.- Returns:
- a Builder to be able to create a
AnnotationRoutingStrategy
-
defaultStrategy
Instantiate a defaultAnnotationRoutingStrategy.The
annotationTypeis defaulted toRoutingKeyand thefallbackRoutingStrategytoUnresolvedRoutingKeyPolicy.RANDOM_KEY.- Returns:
- a default
AnnotationRoutingStrategy
-
doResolveRoutingKey
Description copied from class:AbstractRoutingStrategyResolve the Routing Key for the givencommand.- Specified by:
doResolveRoutingKeyin classAbstractRoutingStrategy- Parameters:
command- the command to resolve the routing key for- Returns:
- the String representing the Routing Key, or
nullif unresolved
-
builder()