Package org.axonframework.queryhandling
Class DefaultQueryGateway
java.lang.Object
org.axonframework.queryhandling.DefaultQueryGateway
- All Implemented Interfaces:
MessageDispatchInterceptorSupport<QueryMessage<?,,?>> QueryGateway
Implementation of the QueryGateway interface that allows the registration of dispatchInterceptors.
- Since:
- 3.1
- Author:
- Marc Gathier, Allard Buijze, Steven van Beelen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aDefaultQueryGateway. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aDefaultQueryGatewaybased on the fields contained in theDefaultQueryGateway.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic DefaultQueryGateway.Builderbuilder()Instantiate a Builder to be able to create aDefaultQueryGateway.<R,Q> CompletableFuture <R> query(String queryName, Q query, ResponseType<R> responseType) Sends givenqueryover theQueryBus, expecting a response in the form ofresponseTypefrom a single source.registerDispatchInterceptor(MessageDispatchInterceptor<? super QueryMessage<?, ?>> interceptor) Register the given DispatchInterceptor.<R,Q> Stream <R> scatterGather(String queryName, Q query, ResponseType<R> responseType, long timeout, TimeUnit timeUnit) Sends givenqueryover theQueryBus, expecting a response in the form ofresponseTypefrom several sources.<R,Q> org.reactivestreams.Publisher <R> streamingQuery(String queryName, Q query, Class<R> responseType) <Q,I, U> SubscriptionQueryResult <I, U> subscriptionQuery(String queryName, Q query, ResponseType<I> initialResponseType, ResponseType<U> updateResponseType, int updateBufferSize) Sends givenqueryover theQueryBusand returns result containing initial response and incremental updates (received at the moment the query is sent, until it is cancelled by the caller or closed by the emitting side).<Q,I, U> SubscriptionQueryResult <I, U> subscriptionQuery(String queryName, Q query, ResponseType<I> initialResponseType, ResponseType<U> updateResponseType, SubscriptionQueryBackpressure backpressure, int updateBufferSize) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.queryhandling.QueryGateway
query, query, query, scatterGather, streamingQuery, subscriptionQuery, subscriptionQuery, subscriptionQuery, subscriptionQuery, subscriptionQuery
-
Constructor Details
-
DefaultQueryGateway
Instantiate aDefaultQueryGatewaybased on the fields contained in theDefaultQueryGateway.Builder.Will assert that the
QueryBusis notnull, and will throw anAxonConfigurationExceptionif it isnull.- Parameters:
builder- theDefaultQueryGateway.Builderused to instantiate aDefaultQueryGatewayinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aDefaultQueryGateway.The
dispatchInterceptorsis defaulted to an empty list. TheQueryBusis a hard requirement and as such should be provided.- Returns:
- a Builder to be able to create a
DefaultQueryGateway
-
query
public <R,Q> CompletableFuture<R> query(@Nonnull String queryName, @Nonnull Q query, @Nonnull ResponseType<R> responseType) Description copied from interface:QueryGatewaySends givenqueryover theQueryBus, expecting a response in the form ofresponseTypefrom a single source. Execution may be asynchronous, depending on the QueryBus implementation.- Specified by:
queryin interfaceQueryGateway- Type Parameters:
R- The response class contained in the givenresponseTypeQ- The query class- Parameters:
queryName- AStringdescribing the query to be executedquery- Thequeryto be sentresponseType- TheResponseTypeused for this query- Returns:
- A
CompletableFuturecontaining the query result as dictated by the givenresponseType
-
streamingQuery
public <R,Q> org.reactivestreams.Publisher<R> streamingQuery(String queryName, Q query, Class<R> responseType) Description copied from interface:QueryGatewaySends givenqueryover theQueryBus, expecting a response asPublisherofresponseType. Query is sent oncePublisheris subscribed to. The Streaming query allows a client to stream large result sets. Usage of this method requires Project Reactor on the class path.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 response class contained in the givenresponseTypeQ- The query class- Parameters:
queryName- AStringdescribing the query to be executedquery- Thequeryto be sentresponseType- AClassdescribing the desired response type- Returns:
- A
Publisherstreaming the results as dictated by the givenresponseType.
-
scatterGather
public <R,Q> Stream<R> scatterGather(@Nonnull String queryName, @Nonnull Q query, @Nonnull ResponseType<R> responseType, long timeout, @Nonnull TimeUnit timeUnit) Description copied from interface:QueryGatewaySends givenqueryover theQueryBus, expecting a response in the form ofresponseTypefrom several sources. The stream is completed when atimeoutoccurs or when all results are received. Execution may be asynchronous, depending on the QueryBus implementation.- Specified by:
scatterGatherin interfaceQueryGateway- Type Parameters:
R- The response class contained in the givenresponseTypeQ- The query class- Parameters:
queryName- AStringdescribing the query to be executedquery- Thequeryto be sentresponseType- TheResponseTypeused for this querytimeout- A timeout oflongfor the querytimeUnit- The selectedTimeUnitfor the giventimeout- Returns:
- A stream of results.
-
subscriptionQuery
@Deprecated public <Q,I, SubscriptionQueryResult<I,U> U> subscriptionQuery(@Nonnull String queryName, @Nonnull Q query, @Nonnull ResponseType<I> initialResponseType, @Nonnull ResponseType<U> updateResponseType, @Nullable SubscriptionQueryBackpressure backpressure, int updateBufferSize) Deprecated.in favour of the {subscriptionQuery(String, Object, ResponseType, ResponseType, int)}Description copied from interface:QueryGatewaySends givenqueryover theQueryBusand returns result containing initial response and incremental updates (received at the moment the query is sent, until it is cancelled by the caller or closed by the emitting side).Note: Any
nullresults, on the initial result or the updates, wil lbe filtered out by the QueryGateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
Q- The type of the queryI- The type of the initial responseU- The type of the incremental update- Parameters:
queryName- AStringdescribing query to be executedquery- Thequeryto be sentinitialResponseType- The initial response type used for this queryupdateResponseType- The update response type used for this querybackpressure- The backpressure mechanism to deal with producing of incremental updatesupdateBufferSize- The size of buffer which accumulates updates before subscription to the flux is made- Returns:
- registration which can be used to cancel receiving updates
- See Also:
-
subscriptionQuery
public <Q,I, SubscriptionQueryResult<I,U> U> subscriptionQuery(@Nonnull String queryName, @Nonnull Q query, @Nonnull ResponseType<I> initialResponseType, @Nonnull ResponseType<U> updateResponseType, int updateBufferSize) Description copied from interface:QueryGatewaySends givenqueryover theQueryBusand returns result containing initial response and incremental updates (received at the moment the query is sent, until it is cancelled by the caller or closed by the emitting side).Note: Any
nullresults, on the initial result or the updates, wil lbe filtered out by the QueryGateway. If you require thenullto be returned for the initial and update results, we suggest using theQueryBusinstead.- Specified by:
subscriptionQueryin interfaceQueryGateway- Type Parameters:
Q- the type of the queryI- the type of the initial responseU- the type of the incremental update- Parameters:
queryName- aStringdescribing query to be executedquery- thequeryto be sentinitialResponseType- the initial response type used for this queryupdateResponseType- the update response type used for this queryupdateBufferSize- the size of buffer which accumulates updates before subscription to the flux is made- Returns:
- registration which can be used to cancel receiving updates
- See Also:
-
registerDispatchInterceptor
public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super QueryMessage<?, ?>> interceptor) Description copied from interface:MessageDispatchInterceptorSupportRegister the given DispatchInterceptor. After registration, the interceptor will be invoked for each Message dispatched on the messaging component that it was registered to.- Specified by:
registerDispatchInterceptorin interfaceMessageDispatchInterceptorSupport<QueryMessage<?,?>> - Parameters:
interceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
subscriptionQuery(String, Object, ResponseType, ResponseType, int)}