Annotation Interface QueryHandler
@Documented
@Retention(RUNTIME)
@Target({METHOD,ANNOTATION_TYPE})
@MessageHandler(messageType=QueryMessage.class)
public @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
payloadof theQueryMessage. - 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 entirequery message metadatainjected. - Parameters assignable to
Messagewill have the entireQueryMessageinjected (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 typeMessage. - A parameter of type
ProcessingContextwill inject the active processing context at that moment in time.
- Since:
- 3.1.0
- Author:
- Marc Gathier
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe name of the query this handler listens to, matching to theMessageType.name()from theMessage.type().
-
Element Details
-
queryName
String queryNameThe name of the query 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 query this handler listens to, matching to the
MessageType.name()from theMessage.type().
- Default:
""
-