Class AnnotatedQueryHandlingComponent<T>

java.lang.Object
org.axonframework.messaging.queryhandling.annotation.AnnotatedQueryHandlingComponent<T>
Type Parameters:
T - The target type of this query handling component.
All Implemented Interfaces:
DescribableComponent, MessageHandler, QueryHandler, QueryHandlingComponent

public class AnnotatedQueryHandlingComponent<T> extends Object implements QueryHandlingComponent
Adapter that turns classes with QueryHandler annotated methods into a QueryHandlingComponent.

Each annotated method is subscribed as a QueryHandler at the QueryHandlingComponent with the query name and response type specified by that method.

Since:
3.1.0
Author:
Marc Gathier, Steven van Beelen
  • Constructor Details

    • AnnotatedQueryHandlingComponent

      public AnnotatedQueryHandlingComponent(@Nonnull T annotatedQueryHandler, @Nonnull ParameterResolverFactory parameterResolverFactory, @Nonnull HandlerDefinition handlerDefinition, @Nonnull MessageTypeResolver messageTypeResolver, @Nonnull MessageConverter converter)
      Wraps the given annotatedQueryHandler, allowing it to be subscribed to a QueryBus as a QueryHandlingComponent.
      Parameters:
      annotatedQueryHandler - The object containing the QueryHandler annotated methods.
      parameterResolverFactory - The parameter resolver factory to resolve handler parameters with.
      handlerDefinition - The handler definition used to create concrete handlers.
      messageTypeResolver - The MessageTypeResolver resolving the names for QueryMessages.
      converter - The converter to use for converting the payload of the query to the type expected by the handling method.
  • Method Details

    • handle

      @Nonnull public MessageStream<QueryResponseMessage> handle(@Nonnull QueryMessage query, @Nonnull ProcessingContext context)
      Description copied from interface: QueryHandler
      Handles the given query within the given context.

      The resulting stream may contain zero, one, or N response messages.

      Specified by:
      handle in interface QueryHandler
      Parameters:
      query - The query to handle.
      context - The context to the given command is handled in.
      Returns:
      A MessagesStream of zero, one, or N response messages.
    • supportedQueries

      public Set<QualifiedName> supportedQueries()
      Description copied from interface: QueryHandlingComponent
      All supported queries, referenced through a QualifiedName.
      Specified by:
      supportedQueries in interface QueryHandlingComponent
      Returns:
      All supported queries, referenced through a QualifiedName.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.