org.axonframework.commandhandling.distributed
Class AnnotationRoutingStrategy

java.lang.Object
  extended by org.axonframework.commandhandling.distributed.AbstractRoutingStrategy
      extended by org.axonframework.commandhandling.distributed.AnnotationRoutingStrategy
All Implemented Interfaces:
RoutingStrategy

public class AnnotationRoutingStrategy
extends AbstractRoutingStrategy

RoutingStrategy that expects an 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.

Since:
2.0
Author:
Allard Buijze
See Also:
AnnotationCommandTargetResolver, DistributedCommandBus

Constructor Summary
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.
 
Method Summary
protected  String doResolveRoutingKey(CommandMessage<?> command)
          Resolve the Routing Key for the given command.
 
Methods inherited from class org.axonframework.commandhandling.distributed.AbstractRoutingStrategy
getRoutingKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationRoutingStrategy

public AnnotationRoutingStrategy()
Initializes a Routing Strategy that fails when an incoming command does not define an AggregateIdentifier to base the routing key on.


AnnotationRoutingStrategy

public AnnotationRoutingStrategy(Class<? extends Annotation> annotationType)
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 aggregate.

AnnotationRoutingStrategy

public 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.

Parameters:
unresolvedRoutingKeyPolicy - The policy indication what should be done when a Command does not contain information about the routing key to use.

AnnotationRoutingStrategy

public 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.

Parameters:
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.
Method Detail

doResolveRoutingKey

protected String doResolveRoutingKey(CommandMessage<?> command)
Description copied from class: AbstractRoutingStrategy
Resolve the Routing Key for the given command.

Specified by:
doResolveRoutingKey in class AbstractRoutingStrategy
Parameters:
command - The command to resolve the routing key for
Returns:
the String representing the Routing Key, or null if unresolved.


Copyright © 2010-2016. All Rights Reserved.