Interface QueryHandlingModule.QueryHandlerPhase

All Superinterfaces:
ModuleBuilder<QueryHandlingModule>
Enclosing interface:
QueryHandlingModule

public static interface QueryHandlingModule.QueryHandlerPhase extends ModuleBuilder<QueryHandlingModule>
The query handler configuration phase of the query handling module.

Every registered QueryHandler will be subscribed with the QueryBus of the ApplicationConfigurer this module is given to.

Provides roughly two options for configuring query handlers. Firstly, a query handler can be registered as is, through the queryHandler(QualifiedName, QueryHandler) method. Secondly, if the query handler provides components from the Configuration, a builder of the query handler can be registered through the queryHandler(QualifiedName, ComponentBuilder) method.

  • Method Details

    • queryHandler

      default QueryHandlingModule.QueryHandlerPhase queryHandler(QualifiedName queryName, QueryHandler queryHandler)
      Registers the given queryHandler for the given qualified queryName and responseName within this module.

      Use this query handler registration method when the query handler in question does not require entities or receives entities through another mechanism. Using a MessageTypeResolver to derive the queryName is beneficial to ensure consistent naming across handler subscriptions.

      Once this module is finalized, the query handler will be subscribed with the QueryBus of the ApplicationConfigurer the module is registered on.

      Parameters:
      queryName - The qualified name of the query the given queryHandler can handle.
      queryHandler - The query handler to register with this module.
      Returns:
      The query handler phase of this builder, for a fluent API.
    • queryHandler

      QueryHandlingModule.QueryHandlerPhase queryHandler(QualifiedName queryName, ComponentBuilder<QueryHandler> queryHandlerBuilder)
      Registers the given queryHandlerBuilder for the given qualified queryName within this module.

      Using a MessageTypeResolver to derive the queryName is beneficial to ensure consistent naming across handler subscriptions.

      Once this module is finalized, the query handler from the queryHandlerBuilder will be subscribed with the QueryBus of the ApplicationConfigurer the module is registered on.

      Parameters:
      queryName - The qualified name of the query the QueryHandler created by the given queryHandlerBuilder.
      queryHandlerBuilder - A builder of a QueryHandler. Provides the Configuration to retrieve components from to use during construction of the query handler.
      Returns:
      The query handler phase of this builder, for a fluent API.
    • queryHandlingComponent

      QueryHandlingModule.QueryHandlerPhase queryHandlingComponent(ComponentBuilder<QueryHandlingComponent> handlingComponentBuilder)
      Registers the given handlingComponentBuilder within this module.

      Use this query handler registration method when the query handling component in question does not require entities or receives entities through another mechanism.

      Once this module is finalized, the resulting QueryHandlingComponent from the handlingComponentBuilder will be subscribed with the QueryBus of the ApplicationConfigurer the module is registered on.

      Parameters:
      handlingComponentBuilder - A builder of a QueryHandlingComponent. Provides the Configuration to retrieve components from to use during construction of the query handling component.
      Returns:
      The query handler phase of this builder, for a fluent API.
    • intercepted

      Registers an interceptor to be applied to the query handling component assembled by this module. Multiple calls accumulate interceptors in registration order.
      Parameters:
      interceptorBuilder - builder for the interceptor to apply
      Returns:
      the query handler phase of this builder, for a fluent API
    • autodetectedQueryHandlingComponent

      default QueryHandlingModule.QueryHandlerPhase autodetectedQueryHandlingComponent(ComponentBuilder<Object> handlingComponentBuilder)
      Registers the given handlingComponentBuilder as an AnnotatedQueryHandlingComponent within this module.

      This will scan the given handlingComponentBuilder for methods annotated with QueryHandler and register them as query handlers for the QueryBus of the ApplicationConfigurer.

      Parameters:
      handlingComponentBuilder - A builder of a QueryHandlingComponent. Provides the Configuration to retrieve components from to use during construction of the query handling component.
      Returns:
      The query handler phase of this builder, for a fluent API.
    • withExceptionHandler

      default QueryHandlingModule.QueryHandlerPhase withExceptionHandler(ComponentBuilder<? extends MessageHandlingExceptionHandler<? super QueryMessage>> handlerBuilder)
      Wraps the query handling component with the exception handler built by the given handlerBuilder. When a query handler throws, the exception handler is invoked. Return MessageStream.empty() to suppress the error, MessageStream.failed(Throwable) to propagate it, or a stream of QueryResponseMessage items to substitute results.

      Accepts either a QueryHandlingExceptionHandler (which narrows the return type for substituting QueryResponseMessage items) or a generic MessageHandlingExceptionHandler typed at any supertype of QueryMessage, allowing a single handler implementation (such as a logger) to be reused across command, event, and query phases.

      Multiple calls accumulate handlers; later-registered handlers are applied closer to the handler and see exceptions first.

      Parameters:
      handlerBuilder - builder for the exception handler to apply to the query handling component
      Returns:
      this phase for further configuration