Class SimpleQueryHandlingComponent

java.lang.Object
org.axonframework.messaging.queryhandling.SimpleQueryHandlingComponent
All Implemented Interfaces:
DescribableComponent, MessageHandler, QueryHandler, QueryHandlerRegistry<SimpleQueryHandlingComponent>, QueryHandlingComponent

public class SimpleQueryHandlingComponent extends Object implements QueryHandlingComponent, QueryHandlerRegistry<SimpleQueryHandlingComponent>
A simple implementation of the QueryHandlingComponent interface, allowing for easy registration of QueryHandlers and other QueryHandlingComponents.

Registered subcomponents are preferred over registered query handlers when handling a query.

Since:
5.0.0
Author:
Steven van Beelen
  • Method Details

    • create

      public static SimpleQueryHandlingComponent create(@Nonnull String name)
      Instantiates a simple QueryHandlingComponent that is able to handle query and delegate them to subcomponents.
      Parameters:
      name - The name of the component, used for describing the component.
      Returns:
      A simple QueryHandlingComponent instance with the given name.
    • subscribe

      public SimpleQueryHandlingComponent subscribe(@Nonnull QualifiedName queryName, @Nonnull QueryHandler handler)
      Description copied from interface: QueryHandlerRegistry
      Subscribe the given queryHandler for queries and response of the given queryName.

      If a subscription already exists for the queryName, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or new handler gets the subscription.

      Specified by:
      subscribe in interface QueryHandlerRegistry<SimpleQueryHandlingComponent>
      Parameters:
      queryName - The fully qualified name of the query
      handler - The handler instance that handles queries for the given queryName.
      Returns:
      This registry for fluent interfacing.
    • subscribe

      public SimpleQueryHandlingComponent subscribe(@Nonnull QueryHandlingComponent handlingComponent)
      Description copied from interface: QueryHandlerRegistry
      Subscribe the given handlingComponent with this registry.

      Typically invokes QueryHandlerRegistry.subscribe(Set, QueryHandler), using the QueryHandlingComponent.supportedQueries() as the set of compatible handler names the component in question can deal with.

      Specified by:
      subscribe in interface QueryHandlerRegistry<SimpleQueryHandlingComponent>
      Parameters:
      handlingComponent - The query handling component instance to subscribe with this registry.
      Returns:
      This registry for fluent interfacing.
    • 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.