Interface QueryGateway
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
DefaultQueryGateway
This interface provides a friendlier API toward the QueryBus.
- Since:
- 3.1.0
- Author:
- Allard Buijze, Marc Gathier, Milan Savic, Steven van Beelen
-
Method Summary
Modifier and TypeMethodDescriptiondefault <R> CompletableFuture<R> Sends givenqueryover theQueryBus, expecting a single response with the givenresponseTypefrom a single source.default <R> CompletableFuture<R> query(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting a single response with the givenresponseTypefrom a single source.<R> CompletableFuture<R> query(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBus, expecting a single response with the givenresponseTypefrom a single source.default <R> CompletableFuture<List<R>> Sends givenqueryover theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.default <R> CompletableFuture<List<R>> queryMany(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.<R> CompletableFuture<List<R>> queryMany(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.default <R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType) default <R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting a response as aPublisherofresponseType.<R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context) default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, @Nullable ProcessingContext context) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.<R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, @Nullable ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context, int updateBufferSize) Sends givenquerywith the givenmetadataover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.<R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
query
<R> CompletableFuture<R> query(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBus, expecting a single response with the givenresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.- Type Parameters:
R- the generic type of the expected response- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typecontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
CompletableFuturecontaining a single query response of typeresponseType
-
query
Sends givenqueryover theQueryBus, expecting a single response with the givenresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.- Type Parameters:
R- the generic type of the expected response- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response type- Returns:
- a
CompletableFuturecontaining a single query response of typeresponseType - See Also:
-
query
default <R> CompletableFuture<R> query(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting a single response with the givenresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryandmetadataare wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata. The providedmetadatais attached afterward in this case.Implementations must override this method to support attaching the given
metadata; the default implementation throws anUnsupportedOperationException.- Type Parameters:
R- the generic type of the expected response- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typemetadata- the metadata to attach to thequerycontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
CompletableFuturecontaining a single query response of typeresponseType - Since:
- 5.3.0
-
queryMany
<R> CompletableFuture<List<R>> queryMany(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typecontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
CompletableFuturecontaining a list of query responses of typeresponseType
-
queryMany
Sends givenqueryover theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response type- Returns:
- a
CompletableFuturecontaining a list of query responses of typeresponseType - See Also:
-
queryMany
default <R> CompletableFuture<List<R>> queryMany(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.Execution may be asynchronous, depending on the
QueryBusimplementation.The given
queryandmetadataare wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata. The providedmetadatais attached afterward in this case.Implementations must override this method to support attaching the given
metadata; the default implementation throws anUnsupportedOperationException.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typemetadata- the metadata to attach to thequerycontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
CompletableFuturecontaining a list of query responses of typeresponseType - Since:
- 5.3.0
-
streamingQuery
<R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBus, expecting a response as aPublisherofresponseType.The
queryis sent once thePublisheris 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Publisheris 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. UseFlux.from(publisher)to convert to Flux stream.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typecontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType
-
streamingQuery
Sends givenqueryover theQueryBus, expecting a response as aPublisherofresponseType.The
queryis sent once thePublisheris 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Publisheris 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. UseFlux.from(publisher)to convert to Flux stream.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response type- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType - See Also:
-
streamingQuery
default <R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context) Sends givenquerywith the givenmetadatain the providedcontext(if available) over theQueryBus, expecting a response as aPublisherofresponseType.The
queryis sent once thePublisheris subscribed to. SeestreamingQuery(Object, Class)for the streaming semantics and Project Reactor requirements.The given
queryandmetadataare wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata. The providedmetadatais attached afterward in this case.Implementations must override this method to support attaching the given
metadata; the default implementation throws anUnsupportedOperationException.- Type Parameters:
R- the generic type of the expected response(s)- Parameters:
query- thequeryto be sentresponseType- aClassdescribing the desired response typemetadata- the metadata to attach to thequerycontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType - Since:
- 5.3.0
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris subscribed to. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial result and the updatecontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType
-
subscriptionQuery
Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris subscribed to. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial result and the update- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType
-
subscriptionQuery
<R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, @Nullable ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris subscribed to. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial result and the updatecontext- the processing context, if any, to dispatch the givenqueryinupdateBufferSize- the size of buffer which accumulates updates before a subscription to theFluxis made- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Metadata metadata, @Nullable ProcessingContext context, int updateBufferSize) Sends givenquerywith the givenmetadataover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris subscribed to. Furthermore, updates 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
queryandmetadataare wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata. The providedmetadatais attached afterward in this case.Implementations must override this method to support attaching the given
metadata; the default implementation throws anUnsupportedOperationException.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial result and the updatemetadata- the metadata to attach to thequerycontext- the processing context, if any, to dispatch the givenqueryinupdateBufferSize- the size of buffer which accumulates updates before a subscription to theFluxis made- Returns:
- a
Publisherstreaming the results as dictated by the givenresponseType - Since:
- 5.3.0
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, @Nullable ProcessingContext context) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update. The givenmapperis used to map theQueryResponseMessageto the desired object type. To distinguish between the initial result and the update, the givenmappercan check whether the givenresponseMessageis an instance ofSubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.The
queryis sent upon invocation of this method. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial resultmapper- aFunctionthat maps theQueryResponseMessageto the desired responsecontext- the processing context, if any, to dispatch the givenqueryin- Returns:
- a
Publisherwhich can be used to cancel receiving update - See Also:
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update. The givenmapperis used to map theQueryResponseMessageto the desired object type. To distinguish between the initial result and the update, the givenmappercan check whether the givenresponseMessageis an instance ofSubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.The
queryis sent upon invocation of this method. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.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- thequeryto be sentresponseType- the response type returned by this query as the initial resultmapper- aFunctionthat maps theQueryResponseMessageto the desired response- Returns:
- a
Publisherwhich can be used to cancel receiving update - See Also:
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update. The givenmapperis used to map theQueryResponseMessageto the desired object type. To distinguish between the initial result and the update, the givenmappercan check whether the givenresponseMessageis an instance ofSubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.The
queryis sent upon invocation of this method. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.- Type Parameters:
R- the type payload to map the responses to- Parameters:
query- thequeryto be sentresponseType- the response type returned by this query as the initial resultupdateBufferSize- the size of the buffer which accumulates updates to be processed- Returns:
- a
Publisherwhich can be used to cancel receiving update - See Also:
-
subscriptionQuery
<R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, @Nullable ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update. The givenmapperis used to map theQueryResponseMessageto the desired object type. To distinguish between the initial result and the update, the givenmappercan check whether the givenresponseMessageis an instance ofSubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.The
queryis sent upon invocation of this method. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.- Type Parameters:
R- the type payload to map the responses to- Parameters:
query- thequeryto be sentresponseType- the response type returned by this query as the initial resultmapper- aFunctionthat maps theQueryResponseMessageto the desired response; messages for which the mapper returns anullvalue are filtered outcontext- the processing context, if any, to dispatch the givenqueryinupdateBufferSize- the size of the buffer which accumulates updates to be processed- Returns:
- a
Publisherwhich can be used to cancel receiving update - See Also:
-
subscriptionQuery
default <R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, Function<QueryResponseMessage, R> mapper, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update. The givenmapperis used to map theQueryResponseMessageto the desired object type. To distinguish between the initial result and the update, the givenmappercan check whether the givenresponseMessageis an instance ofSubscriptionQueryUpdateMessage. In that case the message is considered an update, otherwise it is considered the initial result.The
queryis sent upon invocation of this method. Furthermore, updates 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
queryis wrapped as the payload of theQueryMessagethat is eventually posted on theQueryBus, unless thequeryalready implementsMessage. In that case, aQueryMessageis constructed from that message's payload andMetadata.Note that any
nullresults, on the initial result or the update, will be filtered out by the gateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.- Type Parameters:
R- the type payload to map the responses to- Parameters:
query- thequeryto be sentresponseType- the response type returned by this query as the initial resultmapper- aFunctionthat maps theQueryResponseMessageto the desired response; messages for which the mapper returns anullvalue are filtered outupdateBufferSize- the size of the buffer which accumulates updates to be processed- Returns:
- a
Publisherwhich can be used to cancel receiving update - See Also:
-