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 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.
DistributedCommandBus| Modifier and Type | Class and Description |
|---|---|
static class |
AnnotationRoutingStrategy.Builder
Builder class to instantiate a
AnnotationRoutingStrategy. |
| Modifier | Constructor and Description |
|---|---|
|
AnnotationRoutingStrategy()
Deprecated.
in favor of the
builder() |
protected |
AnnotationRoutingStrategy(AnnotationRoutingStrategy.Builder builder)
Instantiate a
AnnotationRoutingStrategy based on the fields contained in the given builder. |
|
AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
Deprecated.
in favor of the
builder() |
|
AnnotationRoutingStrategy(Class<? extends Annotation> annotationType,
UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
Deprecated.
in favor of the
builder() |
|
AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
Deprecated.
in favor of the
builder() |
| Modifier and Type | Method and Description |
|---|---|
static AnnotationRoutingStrategy.Builder |
builder()
Instantiate a Builder to be able to create a
AnnotationRoutingStrategy. |
static AnnotationRoutingStrategy |
defaultStrategy()
Instantiate a default
AnnotationRoutingStrategy. |
protected String |
doResolveRoutingKey(CommandMessage<?> command)
Resolve the Routing Key for the given
command. |
getRoutingKeyprotected AnnotationRoutingStrategy(AnnotationRoutingStrategy.Builder builder)
AnnotationRoutingStrategy based on the fields contained in the given builder.builder - the AnnotationRoutingStrategy.Builder used to instantiate a AnnotationRoutingStrategy instance@Deprecated public AnnotationRoutingStrategy()
builder()RoutingKey to base the routing on.@Deprecated public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
builder()annotationType - the type of annotation marking the field or method providing the identifier of the targeted
model@Deprecated public AnnotationRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
builder()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 use@Deprecated public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType, UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy)
builder()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 usepublic static AnnotationRoutingStrategy.Builder builder()
AnnotationRoutingStrategy.
The annotationType is defaulted to RoutingKey and the fallbackRoutingStrategy to UnresolvedRoutingKeyPolicy.RANDOM_KEY.
AnnotationRoutingStrategypublic static AnnotationRoutingStrategy defaultStrategy()
AnnotationRoutingStrategy.
The annotationType is defaulted to RoutingKey and the fallbackRoutingStrategy to UnresolvedRoutingKeyPolicy.RANDOM_KEY.
AnnotationRoutingStrategyprotected String doResolveRoutingKey(@Nonnull CommandMessage<?> command)
AbstractRoutingStrategycommand.doResolveRoutingKey in class AbstractRoutingStrategycommand - the command to resolve the routing key fornull if unresolvedCopyright © 2010–2023. All rights reserved.