Annotation Interface EventHandler


Annotation to be placed on methods that can handle 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 payload of the EventMessage.
  • Parameters annotated with MetadataValue will resolve to the Metadata value 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 Metadata will have the entire event message metadata injected.
  • Parameters of type Instant (or any of its super classes or implemented interfaces) will resolve to the timestamp of the EventMessage. This is the time at which the Event was generated.
  • Parameters assignable to Message will have the entire EventMessage injected (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 type Message.
  • A parameter of type ProcessingContext will 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:
  • Element Details

    • eventName

      String eventName
      The name of the event this handler listens to, matching to the MessageType.name() from the Message.type().

      When not defined the MessageTypeResolver will 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 the Message.type().
      Default:
      ""
    • payloadType

      Class<?> payloadType
      The 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