Annotation Interface SagaEventHandler


Method-level annotation indicating that the annotated method is an event handler method for the saga instance.

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 Event message
  • Parameters annotated with @MetaDataValue will resolve to the Meta Data value with the key as indicated on the annotation. If required is false (default), null is passed when the meta data value is not present. If required is true, the resolver will not match and prevent the method from being invoked when the meta data value is not present.
  • Parameters of type MetaData will have the entire Meta Data of an Event Message 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, even if generic parameters would suggest otherwise. 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.
  • When using Spring and <axon:annotation-config/> is declared, any other parameters will resolve to autowired beans, if exactly one autowire candidate is available in the application context. This allows you to inject resources directly into @SagaEventHandler annotated methods.

For each event, only a single annotated method will be invoked. This method is resolved in the following order

  1. First, the event handler methods of the actual class (at runtime) are searched
  2. If a method is found with a parameter that the domain event can be assigned to, it is marked as eligible
  3. After a class has been evaluated (but before any super class), the most specific event handler method is called. That means that if an event handler for a class A and one for a class B are eligible, and B is a subclass of A, then the method with a parameter of type B will be chosen
  4. If no method is found in the actual class, its super class is evaluated.
  5. If still no method is found, the event listener ignores the event
Since:
0.7
Author:
Allard Buijze
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The property in the event that will provide the value to find the Saga instance.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The type of AssociationResolver that will resolve the association property value.
    The key in the AssociationValue to use.
    The type of event this method handles.
  • Element Details

    • associationProperty

      String associationProperty
      The property in the event that will provide the value to find the Saga instance. Typically, this value is an aggregate identifier of an aggregate that a specific saga monitors.
    • keyName

      String keyName
      The key in the AssociationValue to use. Optional. Should only be configured if that property is different than the value given by associationProperty().
      Default:
      ""
    • payloadType

      Class<?> payloadType
      The type of event this method handles. If specified, this handler will only be invoked for message that have a payload assignable to the given payload type. If unspecified, the first parameter of the method defines the type of supported event.
      Default:
      java.lang.Object.class
    • associationResolver

      Class<? extends AssociationResolver> associationResolver
      The type of AssociationResolver that will resolve the association property value. Defaults to finding the association property in the payload.
      Default:
      org.axonframework.modelling.saga.PayloadAssociationResolver.class