Annotation Interface EventHandler
events, thus making them
EventHandlers.
Event handler annotated methods are typically subscribed with a
EventProcessor as part of an
AnnotatedEventHandlingComponent.
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 theEventMessage. - 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 entireevent message metadatainjected. - Parameters of type
Instant(or any of its super classes or implemented interfaces) will resolve to thetimestampof theEventMessage. This is the time at which the Event was generated. - Parameters assignable to
Messagewill have the entireEventMessageinjected (if the message is assignable to that parameter). If the first parameter is of type message, it effectively matches an event 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.
For each event, all matching methods will be invoked per object instance with annotated methods. If still method is found, the event listener ignores the event.
Note: if there are two event handler methods accepting the same argument, the order in which they are invoked is undefined.
- Since:
- 0.1.0
- Author:
- Allard Buijze
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe name of the event this handler listens to, matching to theMessageType.name()from theMessage.type().Class<?> The representation of the event this method requires.
-
Element Details
-
eventName
String eventNameThe name of the event 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 event this handler listens to, matching to the
MessageType.name()from theMessage.type().
- Default:
""
-
payloadType
Class<?> payloadTypeThe representation of the event this method requires. This is an indication for the framework to convert the actual payload representation as the message is delivered with, to the configured representation.Optional. If unspecified, the first parameter of the method defines the expected payload representation.
- Returns:
- The type of the event this method handles.
- Default:
java.lang.Object.class
-