Annotation Interface CommandHandler
commands, thus making them
CommandHandlers.
Command handler annotated methods are typically subscribed with a
CommandBus as part of an
AnnotatedCommandHandlingComponent. This annotation can also be placed directly on entity children (read: an
entity contained in another entity) to have it handle the commands directly.
The parameters of the annotated method are resolved using parameter resolvers. Axon provides a number of parameter resolvers that allow you to use the following parameter types:
- The first parameter is always the
payloadof theCommandMessage. - Parameters annotated with
MetadataValuewill resolve to theMetadatavalue with the key as indicated on the annotation. If required is false (default), null is passed when the metadata value is not present. If required is true, the resolver will not match and prevent the method from being invoked when the metadata value is not present. - Parameters of type
Metadatawill have the entirecommand message metadatainjected. - Parameters assignable to
Messagewill have the entireCommandMessageinjected (if the message is assignable to that parameter). If the first parameter is of type message, it effectively matches a command of any type. Due to type erasure, Axon cannot detect what parameter is expected. In such case, it is best to declare a parameter of the payload type, followed by a parameter of typeMessage. - A parameter of type
ProcessingContextwill inject the active processing context at that moment in time.
- Since:
- 0.5.0
- Author:
- Allard Buijze
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe name of the command this handler listens to, matching to theMessageType.name()from theMessage.type().Class<?> The type of payload expected by this handler.The property of the command to be used as a routing key towards this command handler instance.
-
Element Details
-
commandName
String commandNameThe name of the command this handler listens to, matching to theMessageType.name()from theMessage.type().When not defined the
MessageTypeResolverwill derive the name based on the payload type (thus the first parameter) of the annotated method.- Returns:
- The name of the command this handler listens to, matching to the
MessageType.name()from theMessage.type().
- Default:
""
-
routingKey
String routingKeyThe property of the command to be used as a routing key towards this command handler instance.If multiple handlers instances are available, a sending component is responsible to route commands with the same routing key value to the correct instance.
- Returns:
- The property of the command to use as routing key.
- Default:
""
-
payloadType
Class<?> payloadTypeThe type of payload expected by this handler.Defaults to the expected types expresses by (primarily the first) parameters of the annotated method.
- Returns:
- The payload type expected by this handler.
- Default:
java.lang.Object.class
-