Class DefaultQueryGateway

java.lang.Object
org.axonframework.messaging.queryhandling.gateway.DefaultQueryGateway
All Implemented Interfaces:
DescribableComponent, QueryGateway

public class DefaultQueryGateway extends Object implements QueryGateway
Default implementation of the QueryGateway interface.
Since:
3.1.0
Author:
Allard Buijze, Marc Gathier, Steven van Beelen
  • Constructor Details

  • Method Details

    • query

      @Nonnull public <R> CompletableFuture<R> query(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus, expecting a single response with the given responseType from a single source.

      Execution may be asynchronous, depending on the QueryBus implementation.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Specified by:
      query in interface QueryGateway
      Type Parameters:
      R - The generic type of the expected response.
      Parameters:
      query - The query to be sent.
      responseType - A Class describing the desired response type.
      context - The processing context, if any, to dispatch the given query in.
      Returns:
      A CompletableFuture containing a single query response of type responseType.
    • queryMany

      @Nonnull public <R> CompletableFuture<List<R>> queryMany(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus, expecting multiple responses in the form of responseType from a single source.

      Execution may be asynchronous, depending on the QueryBus implementation.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Specified by:
      queryMany in interface QueryGateway
      Type Parameters:
      R - The generic type of the expected response(s).
      Parameters:
      query - The query to be sent.
      responseType - A Class describing the desired response type.
      context - The processing context, if any, to dispatch the given query in.
      Returns:
      A CompletableFuture containing a list of query responses of type responseType.
    • streamingQuery

      @Nonnull public <R> org.reactivestreams.Publisher<R> streamingQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus, expecting a response as a Publisher of responseType.

      The query is sent once the Publisher is subscribed to. The streaming query allows a client to stream large result sets. Usage of this method requires Project Reactor on the class path.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Publisher is used for backwards compatibility reason, for clients that don't have Project Reactor on class path. Check Reactor Extension for native Flux type and more. Use Flux.from(publisher) to convert to Flux stream.

      Specified by:
      streamingQuery in interface QueryGateway
      Type Parameters:
      R - The generic type of the expected response(s).
      Parameters:
      query - The query to be sent.
      responseType - A Class describing the desired response type.
      context - The processing context, if any, to dispatch the given query in.
      Returns:
      A Publisher streaming the results as dictated by the given responseType.
    • subscriptionQuery

      @Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus as a subscription query, combining the initial result and emitted update as a Publisher of the given responseType.

      The query is sent once the Publisher is subscribed to. Furthermore, update are received at the moment the query is sent, and until it is cancelled by the caller or closed by the emitting side.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Note that any null results, on the initial result or the update, wil lbe filtered out by the gateway. If you require the null to be returned for the initial and update results, we suggest using the QueryBus instead.

      The returned Publisher must be subscribed to and consumed from before the buffer fills up. Once the buffer is full, any attempt to add an update will complete the stream with an exception.

      Specified by:
      subscriptionQuery in interface QueryGateway
      Type Parameters:
      R - The type of all the responses.
      Parameters:
      query - The query to be sent.
      responseType - The response type returned by this query as the initial result and the update.
      Returns:
      A Publisher streaming the results as dictated by the given responseType.
    • subscriptionQuery

      @Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context, int updateBufferSize)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus as a subscription query, combining the initial result and emitted update as a Publisher of the given responseType.

      The query is sent once the Publisher is subscribed to. Furthermore, update are received at the moment the query is sent, and until it is cancelled by the caller or closed by the emitting side.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Note that any null results, on the initial result or the update, will be filtered out by the gateway. If you require the null to be returned for the initial and update results, we suggest using the QueryBus instead.

      The returned Publisher must be subscribed to and consumed from before the buffer fills up. Once the buffer is full, any attempt to add an update will complete the stream with an exception.

      Specified by:
      subscriptionQuery in interface QueryGateway
      Type Parameters:
      R - The type of all the responses.
      Parameters:
      query - The query to be sent.
      responseType - The response type returned by this query as the initial result and the update.
      context - The processing context, if any, to dispatch the given query in.
      updateBufferSize - The size of buffer which accumulates update before a subscription to the Flux is made.
      Returns:
      A Publisher streaming the results as dictated by the given responseType.
    • subscriptionQuery

      @Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, int updateBufferSize)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus and returns a Publisher supplying the initial update followed by the update. The given mapper is used to map the QueryResponseMessage to the desired object type. To distinguish between the initial result and the update, the given mapper can check whether the given responseMessage is an instance of SubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.

      The query is sent upon invocation of this method. Furthermore, update are received at the moment the query is sent, and until the subscription to the Publisher is canceled by the caller or closed by the emitting side.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Note that any null results, on the initial result or the update, will be filtered out by the gateway. If you require the null to be returned for the initial and update results, we suggest using the QueryBus instead.

      Specified by:
      subscriptionQuery in interface QueryGateway
      Type Parameters:
      R - The type payload to map the responses to.
      Parameters:
      query - The query to be sent.
      responseType - The response type returned by this query as the initial result
      updateBufferSize - The size of the buffer which accumulates update to be processed.
      Returns:
      Registration which can be used to cancel receiving update.
      See Also:
    • subscriptionQuery

      @Nonnull public <T> org.reactivestreams.Publisher<T> subscriptionQuery(@Nonnull Object query, @Nonnull Class<T> responseType, @Nonnull Function<QueryResponseMessage,T> mapper, @Nullable ProcessingContext context, int updateBufferSize)
      Description copied from interface: QueryGateway
      Sends given query over the QueryBus and returns a Publisher supplying the initial update followed by the update. The given mapper is used to map the QueryResponseMessage to the desired object type. To distinguish between the initial result and the update, the given mapper can check whether the given responseMessage is an instance of SubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.

      The query is sent upon invocation of this method. Furthermore, update are received at the moment the query is sent, and until the subscription to the Publisher is canceled by the caller or closed by the emitting side.

      The given query is wrapped as the payload of the QueryMessage that is eventually posted on the QueryBus, unless the query already implements Message. In that case, a QueryMessage is constructed from that message's payload and Metadata.

      Note that any null results, on the initial result or the update, will be filtered out by the gateway. If you require the null to be returned for the initial and update results, we suggest using the QueryBus instead.

      Specified by:
      subscriptionQuery in interface QueryGateway
      Type Parameters:
      T - The type payload to map the responses to.
      Parameters:
      query - The query to be sent.
      responseType - The response type returned by this query as the initial result
      mapper - A Function that maps the QueryResponseMessage to the desired response. Messages for which the mapper returns a null value are filtered out.
      context - The processing context, if any, to dispatch the given query in.
      updateBufferSize - The size of the buffer which accumulates update to be processed.
      Returns:
      Registration which can be used to cancel receiving update.
      See Also:
    • 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.