Class AnnotationRoutingStrategy
java.lang.Object
org.axonframework.messaging.commandhandling.annotation.AnnotationRoutingStrategy
- All Implemented Interfaces:
RoutingStrategy
RoutingStrategy that expects an
Command (meta-)annotation on the command message's payload. Commands are
routed based on an identifier annotated with the Command. 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.0
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiate an annotationRoutingStrategy.AnnotationRoutingStrategy(Class<? extends Annotation> annotationType) Instantiate an annotationRoutingStrategy. -
Method Summary
Modifier and TypeMethodDescriptiongetRoutingKey(CommandMessage command) Generates a routing key for the givencommand.
-
Constructor Details
-
AnnotationRoutingStrategy
public AnnotationRoutingStrategy() -
AnnotationRoutingStrategy
Instantiate an annotationRoutingStrategy. TheannotationTypeattribute routingKey is used to indicate which field to use as routing key.- Parameters:
annotationType- The annotation specifying the field to check the payload for.
-
-
Method Details
-
getRoutingKey
Description copied from interface:RoutingStrategyGenerates a routing key for the givencommand.Commands that should be handled by the same segment, should result in the same routing key.
- Specified by:
getRoutingKeyin interfaceRoutingStrategy- Parameters:
command- The command to create a routing key for.- Returns:
- The routing key for the command.
-