Interface QueryBus
- All Superinterfaces:
MessageDispatchInterceptorSupport<QueryMessage<?,,?>> MessageHandlerInterceptorSupport<QueryMessage<?,?>>
- All Known Implementing Classes:
AxonServerQueryBus,SimpleQueryBus
QueryMessage.getQueryName() and QueryMessage.getResponseType() on the query bus. There may be multiple handlers for each combination of
queryName/responseType.- Since:
- 3.1
- Author:
- Marc Gathier, Allard Buijze
-
Method Summary
Modifier and TypeMethodDescription<Q,R> CompletableFuture <QueryResponseMessage<R>> query(QueryMessage<Q, R> query) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName and responseType.Gets theQueryUpdateEmitterassociated with thisQueryBus.<Q,R> Stream <QueryResponseMessage<R>> scatterGather(QueryMessage<Q, R> query, long timeout, TimeUnit unit) Dispatch the givenqueryto all QueryHandlers subscribed to the givenquery's queryName/responseType.default <Q,R> org.reactivestreams.Publisher <QueryResponseMessage<R>> streamingQuery(StreamingQueryMessage<Q, R> query) Builds aPublisherof responses to the givenquery.<R> Registrationsubscribe(String queryName, Type responseType, MessageHandler<? super QueryMessage<?, R>> handler) Subscribe the givenhandlerto queries with the givenqueryNameandresponseType.default <Q,I, U> SubscriptionQueryResult <QueryResponseMessage<I>, SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q, I, U> query) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName/initialResponseType/updateResponseType.default <Q,I, U> SubscriptionQueryResult <QueryResponseMessage<I>, SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q, I, U> query, int updateBufferSize) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName/initialResponseType/updateResponseType.default <Q,I, U> SubscriptionQueryResult <QueryResponseMessage<I>, SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q, I, U> query, SubscriptionQueryBackpressure backpressure, int updateBufferSize) Deprecated.Methods inherited from interface org.axonframework.messaging.MessageDispatchInterceptorSupport
registerDispatchInterceptorMethods inherited from interface org.axonframework.messaging.MessageHandlerInterceptorSupport
registerHandlerInterceptor
-
Method Details
-
subscribe
<R> Registration subscribe(@Nonnull String queryName, @Nonnull Type responseType, @Nonnull MessageHandler<? super QueryMessage<?, R>> handler) Subscribe the givenhandlerto queries with the givenqueryNameandresponseType. Multiple handlers may subscribe to the same combination of queryName/responseType.- Parameters:
queryName- the name of the query request to subscriberesponseType- the type of response the subscribed component answers withhandler- a handler that implements the query- Returns:
- a handle to un-subscribe the query handler
-
query
Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName and responseType. This method returns all values returned by the Query Handler as a Collection. This may or may not be the exact collection as defined in the Query Handler.If the Query Handler defines a single return object (i.e. not a collection or array), that object is returned as the sole entry in a singleton collection.
When no handlers are available that can answer the given
query, the returned CompletableFuture will be completed with aNoHandlerForQueryException.- Type Parameters:
Q- the payload type of the queryR- the response type of the query- Parameters:
query- the query- Returns:
- a CompletableFuture that resolves when the response is available
-
streamingQuery
default <Q,R> org.reactivestreams.Publisher<QueryResponseMessage<R>> streamingQuery(StreamingQueryMessage<Q, R> query) Builds aPublisherof responses to the givenquery. The actual query is not dispatched until there is a subscription to the result. The query is dispatched to a single query handler. Implementations may opt for invoking several query handlers and then choosing a response from single one for performance or resilience reasons.When no handlers are available that can answer the given
query, the return Publisher will be completed with aNoHandlerForQueryException.- Type Parameters:
Q- the payload type of the streaming queryR- the response type of the streaming query- Parameters:
query- the streaming query message- Returns:
- a Publisher of responses
-
scatterGather
<Q,R> Stream<QueryResponseMessage<R>> scatterGather(@Nonnull QueryMessage<Q, R> query, long timeout, @Nonnull TimeUnit unit) Dispatch the givenqueryto all QueryHandlers subscribed to the givenquery's queryName/responseType. Returns a stream of results which blocks until all handlers have processed the request or when the timeout occurs.If no handlers are available to provide a result, or when all available handlers throw an exception while attempting to do so, the returned Stream is empty.
Note that any terminal operation (such as
Stream.forEach(Consumer)) on the Stream may cause it to block until thetimeouthas expired, awaiting additional data to include in the stream.- Type Parameters:
Q- the payload type of the queryR- the response type of the query- Parameters:
query- the querytimeout- time to wait for resultsunit- unit for the timeout- Returns:
- stream of query results
-
subscriptionQuery
default <Q,I, SubscriptionQueryResult<QueryResponseMessage<I>,U> SubscriptionQueryUpdateMessage<U>> subscriptionQuery(@Nonnull SubscriptionQueryMessage<Q, I, U> query) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName/initialResponseType/updateResponseType. The result is lazily created and there will be no execution of the query handler before there is a subscription to the initial result. In order not to miss updates, the query bus will queue all updates which happen after the subscription query is done and once the subscription to the flux is made, these updates will be emitted.If there is an error during retrieving or consuming initial result, stream for incremental updates is NOT interrupted.
If there is an error during emitting an update, subscription is cancelled causing further emits not reaching the destination.
The buffer size which accumulates the updates (not to be missed) is
Queues.SMALL_BUFFER_SIZE.- Type Parameters:
Q- the payload type of the queryI- the response type of the queryU- the incremental response types of the query- Parameters:
query- the query- Returns:
- query result containing initial result and incremental updates
-
subscriptionQuery
@Deprecated default <Q,I, SubscriptionQueryResult<QueryResponseMessage<I>,U> SubscriptionQueryUpdateMessage<U>> subscriptionQuery(@Nonnull SubscriptionQueryMessage<Q, I, U> query, SubscriptionQueryBackpressure backpressure, int updateBufferSize) Deprecated.in favour of using {subscriptionQuery(SubscriptionQueryMessage, int)}Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName/initialResponseType/updateResponseType. The result is lazily created and there will be no execution of the query handler before there is a subscription to the initial result. In order not to miss updates, the query bus will queue all updates which happen after the subscription query is done and once the subscription to the flux is made, these updates will be emitted.If there is an error during retrieving or consuming initial result, stream for incremental updates is NOT interrupted.
If there is an error during emitting an update, subscription is cancelled causing further emits not reaching the destination.
Provided backpressure mechanism will be used to deal with fast emitters.
- Type Parameters:
Q- the payload type of the queryI- the response type of the queryU- the incremental response types of the query- Parameters:
query- the querybackpressure- the backpressure mechanism to be used for emitting updatesupdateBufferSize- the size of buffer which accumulates updates before subscription to thefluxis made- Returns:
- query result containing initial result and incremental updates
-
subscriptionQuery
default <Q,I, SubscriptionQueryResult<QueryResponseMessage<I>,U> SubscriptionQueryUpdateMessage<U>> subscriptionQuery(@Nonnull SubscriptionQueryMessage<Q, I, U> query, int updateBufferSize) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName/initialResponseType/updateResponseType. The result is lazily created and there will be no execution of the query handler before there is a subscription to the initial result. In order not to miss updates, the query bus will queue all updates which happen after the subscription query is done and once the subscription to the flux is made, these updates will be emitted.If there is an error during retrieving or consuming initial result, stream for incremental updates is NOT interrupted.
If there is an error during emitting an update, subscription is cancelled causing further emits not reaching the destination.
- Type Parameters:
Q- the payload type of the queryI- the response type of the queryU- the incremental response types of the query- Parameters:
query- the queryupdateBufferSize- the size of buffer which accumulates updates before subscription to thefluxis made- Returns:
- query result containing initial result and incremental updates
-
queryUpdateEmitter
QueryUpdateEmitter queryUpdateEmitter()Gets theQueryUpdateEmitterassociated with thisQueryBus.- Returns:
- the associated
QueryUpdateEmitter
-
subscriptionQuery(SubscriptionQueryMessage, int)}