Class DefaultQueryGateway
- All Implemented Interfaces:
DescribableComponent,QueryGateway
QueryGateway interface.- Since:
- 3.1.0
- Author:
- Allard Buijze, Marc Gathier, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultQueryGateway(QueryBus queryBus, MessageTypeResolver messageTypeResolver, QueryPriorityCalculator priorityCalculator, MessageConverter converter) Initialize theDefaultQueryGatewayto send queries through the givenqueryBus. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.<R> CompletableFuture<R> query(Object query, Class<R> responseType, ProcessingContext context) Sends givenqueryover theQueryBus, expecting a single response with the givenresponseTypefrom a single source.<R> CompletableFuture<List<R>> queryMany(Object query, Class<R> responseType, ProcessingContext context) Sends givenqueryover theQueryBus, expecting multiple responses in the form ofresponseTypefrom a single source.<R> org.reactivestreams.Publisher<R> streamingQuery(Object query, Class<R> responseType, ProcessingContext context) <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.<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.<R> org.reactivestreams.Publisher<R> subscriptionQuery(Object query, Class<R> responseType, ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.<T> org.reactivestreams.Publisher<T> subscriptionQuery(Object query, Class<T> responseType, Function<QueryResponseMessage, T> mapper, ProcessingContext context, int updateBufferSize) Sends givenqueryover theQueryBusand returns aPublishersupplying the initial update followed by the update.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.queryhandling.gateway.QueryGateway
query, queryMany, streamingQuery, subscriptionQuery, subscriptionQuery, subscriptionQuery, subscriptionQuery
-
Constructor Details
-
DefaultQueryGateway
public DefaultQueryGateway(@Nonnull QueryBus queryBus, @Nonnull MessageTypeResolver messageTypeResolver, @Nonnull QueryPriorityCalculator priorityCalculator, @Nonnull MessageConverter converter) Initialize theDefaultQueryGatewayto send queries through the givenqueryBus.The
namesforQueryMessagesare resolved through the givennameResolver.- Parameters:
queryBus- TheQueryBusto send queries on.messageTypeResolver- TheMessageTypeResolverresolving thenamesforQueryMessagesbeing dispatched on thequeryBus.priorityCalculator- TheQueryPriorityCalculatordetermining the priority of queries.converter- The converter to use for converting the result of query handling.
-
-
Method Details
-
query
@Nonnull public <R> CompletableFuture<R> query(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context) Description copied from interface:QueryGatewaySends 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.- Specified by:
queryin interfaceQueryGateway- Type Parameters:
R- The generic type of the expected response.- Parameters:
query- Thequeryto be sent.responseType- AClassdescribing the desired response type.context- The processing context, if any, to dispatch the givenqueryin.- Returns:
- A
CompletableFuturecontaining a single query response of typeresponseType.
-
queryMany
@Nonnull public <R> CompletableFuture<List<R>> queryMany(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context) Description copied from interface:QueryGatewaySends 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.- Specified by:
queryManyin interfaceQueryGateway- Type Parameters:
R- The generic type of the expected response(s).- Parameters:
query- Thequeryto be sent.responseType- AClassdescribing the desired response type.context- The processing context, if any, to dispatch the givenqueryin.- Returns:
- A
CompletableFuturecontaining a list of query responses of typeresponseType.
-
streamingQuery
@Nonnull public <R> org.reactivestreams.Publisher<R> streamingQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context) Description copied from interface:QueryGatewaySends 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.- Specified by:
streamingQueryin interfaceQueryGateway- Type Parameters:
R- The generic type of the expected response(s).- Parameters:
query- Thequeryto be sent.responseType- AClassdescribing the desired response type.context- The processing context, if any, to dispatch the givenqueryin.- Returns:
- A
Publisherstreaming the results as dictated by the givenresponseType.
-
subscriptionQuery
@Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType) Description copied from interface:QueryGatewaySends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris 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
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, wil lbe 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.
- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
R- The type of all the responses.- Parameters:
query- Thequeryto be sent.responseType- 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
@Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, @Nullable ProcessingContext context, int updateBufferSize) Description copied from interface:QueryGatewaySends givenqueryover theQueryBusas a subscription query, combining the initial result and emitted update as aPublisherof the givenresponseType.The
queryis sent once thePublisheris 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
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.
- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
R- The type of all the responses.- Parameters:
query- Thequeryto 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 givenqueryin.updateBufferSize- The size of buffer which accumulates update before a subscription to theFluxis made.- Returns:
- A
Publisherstreaming the results as dictated by the givenresponseType.
-
subscriptionQuery
@Nonnull public <R> org.reactivestreams.Publisher<R> subscriptionQuery(@Nonnull Object query, @Nonnull Class<R> responseType, int updateBufferSize) Description copied from interface:QueryGatewaySends 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, 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
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.- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
R- The type payload to map the responses to.- Parameters:
query- Thequeryto be sent.responseType- The response type returned by this query as the initial resultupdateBufferSize- 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:QueryGatewaySends 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, 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
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.- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
T- The type payload to map the responses to.- Parameters:
query- Thequeryto be sent.responseType- 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 out.context- The processing context, if any, to dispatch the givenqueryin.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
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-