Annotation Interface QueryHandler


Annotation to be placed on methods that can handle queries, thus making them QueryHandlers.

Query handler annotated methods are typically subscribed with a QueryBus as part of an AnnotatedQueryHandlingComponent.

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 QueryMessage.
  • 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 query message metadata injected.
  • Parameters assignable to Message will have the entire QueryMessage injected (if the message is assignable to that parameter). If the first parameter is of type message, it effectively matches a query 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.
Since:
3.1.0
Author:
Marc Gathier