public class AnnotationRoutingStrategy extends AbstractRoutingStrategy
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 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 properObject.toString() method. An inconsistent
toString() method may result in different members using different routing keys for the same identifier.DistributedCommandBus| Constructor and Description |
|---|
AnnotationRoutingStrategy()
Initializes a Routing Strategy that fails when an incoming command does not define a field as the
RoutingKey to base the routing on. |
AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
Initializes a Routing Strategy that uses the given annotation to resolve the targeted identifier.
|
AnnotationRoutingStrategy(Class<? extends Annotation> annotationType,
UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
Initializes a Routing Strategy that uses the given annotation to resolve the targeted identifier and the given
unresolvedRoutingKeyPolicy when an incoming command does not define an Identifier to base the routing key
on. |
AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
Initializes a Routing Strategy that uses the given
unresolvedRoutingKeyPolicy when an incoming
command does not define a RoutingKey annotated field to base the routing on. |
| Modifier and Type | Method and Description |
|---|---|
protected String |
doResolveRoutingKey(CommandMessage<?> command)
Resolve the Routing Key for the given
command. |
getRoutingKeypublic AnnotationRoutingStrategy()
RoutingKey to base the routing on.public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
annotationType - the type of annotation marking the field or method providing the identifier of the targeted
modelpublic AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
unresolvedRoutingKeyPolicy when an incoming
command does not define a RoutingKey annotated field to base the routing on.unresolvedRoutingKeyPolicy - a UnresolvedRoutingKeyPolicy indicating what should be done when a
Command does not contain information about the routing key to usepublic AnnotationRoutingStrategy(Class<? extends Annotation> annotationType, UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
unresolvedRoutingKeyPolicy when an incoming command does not define an Identifier to base the routing key
on.annotationType - the type of annotation marking the field or method providing the identifier of
the targeted modelunresolvedRoutingKeyPolicy - a UnresolvedRoutingKeyPolicy indicating what should be done when a
Command does not contain information about the routing key to useprotected String doResolveRoutingKey(CommandMessage<?> command)
AbstractRoutingStrategycommand.doResolveRoutingKey in class AbstractRoutingStrategycommand - The command to resolve the routing key fornull if unresolved.Copyright © 2010–2020. All rights reserved.