public class AnnotationRoutingStrategy extends AbstractRoutingStrategy
TargetAggregateIdentifier
annotation on the command message's payload. Commands are routed based on the identifier of the aggregate that they
target. This approach ensures that commands to be processed by the same aggregate are dispatched to the same node in
a DistributedCommandBus. See AnnotationCommandTargetResolver
for more details.
This class requires the returned Aggregate Identifiers to implement a proper Object.toString()
method. An
inconsistent toString() method may result in different members using different routing keys for the same identifier.AnnotationCommandTargetResolver
,
DistributedCommandBus
Constructor and Description |
---|
AnnotationRoutingStrategy()
Initializes a Routing Strategy that fails when an incoming command does not define an AggregateIdentifier to
base the routing key 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 AggregateIdentifier 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 an AggregateIdentifier to base the routing key on. |
Modifier and Type | Method and Description |
---|---|
protected String |
doResolveRoutingKey(CommandMessage<?> command)
Resolve the Routing Key for the given
command . |
getRoutingKey
public AnnotationRoutingStrategy()
public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
annotationType
- The type of annotation marking the field or method providing the identifier of the
targeted aggregate.public AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
unresolvedRoutingKeyPolicy
when an incoming
command does not define an AggregateIdentifier to base the routing key on.unresolvedRoutingKeyPolicy
- The policy indication what should be done when a Command does not contain
information about the routing key to use.public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType, UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
unresolvedRoutingKeyPolicy
when an incoming command does not define an AggregateIdentifier to base
the routing key on.annotationType
- The type of annotation marking the field or method providing the identifier of
the targeted aggregate.unresolvedRoutingKeyPolicy
- The policy indication what should be done when a Command does not contain
information about the routing key to use.protected String doResolveRoutingKey(CommandMessage<?> command)
AbstractRoutingStrategy
command
.doResolveRoutingKey
in class AbstractRoutingStrategy
command
- The command to resolve the routing key fornull
if unresolved.Copyright © 2010–2017. All rights reserved.