Interface QueryGateway

All Superinterfaces:
DescribableComponent
All Known Implementing Classes:
DefaultQueryGateway

public interface QueryGateway extends DescribableComponent
Interface towards the Query Handling components of an application.

This interface provides a friendlier API toward the QueryBus.

Since:
3.1.0
Author:
Allard Buijze, Marc Gathier, Milan Savic, Steven van Beelen
  • Method Details

    • query

      @Nonnull <R> CompletableFuture<R> query(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      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.

      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.
    • query

      @Nonnull default <R> CompletableFuture<R> query(@Nonnull Object query, @Nonnull Class<R> responseType)
      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.

      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.
      Returns:
      A CompletableFuture containing a single query response of type responseType.
      See Also:
    • queryMany

      @Nonnull <R> CompletableFuture<List<R>> queryMany(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      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.

      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.
    • queryMany

      @Nonnull default <R> CompletableFuture<List<R>> queryMany(@Nonnull Object query, @Nonnull Class<R> responseType)
      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.

      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.
      Returns:
      A CompletableFuture containing a list of query responses of type responseType.
      See Also:
    • streamingQuery

      @Nonnull <R> org.reactivestreams.Publisher<R> streamingQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      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.

      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.
    • streamingQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> streamingQuery(@Nonnull Object query, @Nonnull Class<R> responseType)
      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.

      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.
      Returns:
      A Publisher streaming the results as dictated by the given responseType.
      See Also:
    • subscriptionQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context)
      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.

      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.
      Returns:
      A Publisher streaming the results as dictated by the given responseType.
    • subscriptionQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType)
      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.

      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 <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context, int updateBufferSize)
      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.

      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 default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nonnull Function<QueryResponseMessage,R> mapper, @Nullable ProcessingContext context)
      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.

      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. To control the buffer size, use subscriptionQuery(Object, Class, Function, ProcessingContext, int).

      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
      mapper - A Function that maps the QueryResponseMessage to the desired response
      context - The processing context, if any, to dispatch the given query in.
      Returns:
      Registration which can be used to cancel receiving update.
      See Also:
    • subscriptionQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nonnull Function<QueryResponseMessage,R> mapper)
      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.

      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. To control the buffer size, use subscriptionQuery(Object, Class, Function, ProcessingContext, int).

      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
      mapper - A Function that maps the QueryResponseMessage to the desired response
      Returns:
      Registration which can be used to cancel receiving update.
      See Also:
    • subscriptionQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, int updateBufferSize)
      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.

      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 <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nonnull Function<QueryResponseMessage,R> mapper, @Nullable ProcessingContext context, int updateBufferSize)
      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.

      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
      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:
    • subscriptionQuery

      @Nonnull default <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nonnull Function<QueryResponseMessage,R> mapper, int updateBufferSize)
      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.

      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
      mapper - A Function that maps the QueryResponseMessage to the desired response. Messages for which the mapper returns a null value are filtered out.
      updateBufferSize - The size of the buffer which accumulates update to be processed.
      Returns:
      Registration which can be used to cancel receiving update.
      See Also: