Class AxonServerQueryBus
- All Implemented Interfaces:
Lifecycle,Distributed<QueryBus>,MessageDispatchInterceptorSupport<QueryMessage<?,,?>> MessageHandlerInterceptorSupport<QueryMessage<?,,?>> QueryBus
QueryBus implementation that connects to Axon Server to submit and receive queries and query responses.
Delegates incoming queries to the provided localSegment.- Since:
- 4.0
- Author:
- Marc Gathier
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate anAxonServerQueryBus.Nested classes/interfaces inherited from interface org.axonframework.lifecycle.Lifecycle
Lifecycle.LifecycleHandler, Lifecycle.LifecycleRegistry -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate aAxonServerQueryBusbased on the fields contained in theAxonServerQueryBus.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic AxonServerQueryBus.Builderbuilder()Instantiate a Builder to be able to create anAxonServerQueryBus.voidDisconnect the query bus from Axon Server, by unsubscribing all known query handlers and aborting all queries in progress.Return the message bus of typeMessageBuswhich is regarded as the local segment for this implementation.<Q,R> CompletableFuture <QueryResponseMessage<R>> query(QueryMessage<Q, R> queryMessage) Dispatch the givenqueryto a single QueryHandler subscribed to the givenquery's queryName and responseType.Gets theQueryUpdateEmitterassociated with thisQueryBus.registerDispatchInterceptor(MessageDispatchInterceptor<? super QueryMessage<?, ?>> dispatchInterceptor) Register the given DispatchInterceptor.registerHandlerInterceptor(MessageHandlerInterceptor<? super QueryMessage<?, ?>> interceptor) Register the givenhandlerInterceptor.voidRegisters the activities to be executed in the various phases of an application's lifecycle.<Q,R> Stream <QueryResponseMessage<R>> scatterGather(QueryMessage<Q, R> queryMessage, long timeout, TimeUnit timeUnit) Dispatch the givenqueryto all QueryHandlers subscribed to the givenquery's queryName/responseType.Shutdown the query bus asynchronously for dispatching queries to Axon Server.voidstart()Start the Axon ServerQueryBusimplementation.<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.<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.<Q,I, U> SubscriptionQueryResult <QueryResponseMessage<I>, SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q, I, U> query, 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.QueryBus
subscriptionQuery
-
Constructor Details
-
AxonServerQueryBus
Instantiate aAxonServerQueryBusbased on the fields contained in theAxonServerQueryBus.Builder.- Parameters:
builder- theAxonServerQueryBus.Builderused to instantiate aAxonServerQueryBusinstance
-
-
Method Details
-
streamingQuery
public <Q,R> org.reactivestreams.Publisher<QueryResponseMessage<R>> streamingQuery(StreamingQueryMessage<Q, R> query) Description copied from interface:QueryBusBuilds 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.- Specified by:
streamingQueryin interfaceQueryBus- 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
-
builder
Instantiate a Builder to be able to create anAxonServerQueryBus.The
QueryPriorityCalculatoris defaulted toQueryPriorityCalculator.defaultQueryPriorityCalculator(), theTargetContextResolverdefaults to a lambda returning theAxonServerConfiguration.getContext()as the context, theExecutorServiceBuilderdefaults toExecutorServiceBuilder.defaultQueryExecutorServiceBuilder(). TheAxonServerConnectionManagerand theQueryBusSpanFactorydefaults to aDefaultQueryBusSpanFactorybacked by aNoOpSpanFactory. TheAxonServerConfiguration, the localQueryBus, theQueryUpdateEmitter, and the message and genericSerializers are hard requirements and as such should be provided.- Returns:
- a Builder to be able to create a
AxonServerQueryBus
-
registerLifecycleHandlers
Description copied from interface:LifecycleRegisters the activities to be executed in the various phases of an application's lifecycle. This could either be at startup, shutdown, or both.- Specified by:
registerLifecycleHandlersin interfaceLifecycle- Parameters:
lifecycle- the lifecycle instance to register the handlers with- See Also:
-
start
public void start()Start the Axon ServerQueryBusimplementation. -
subscribe
public <R> Registration subscribe(@Nonnull String queryName, @Nonnull Type responseType, @Nonnull MessageHandler<? super QueryMessage<?, R>> handler) Description copied from interface:QueryBusSubscribe the givenhandlerto queries with the givenqueryNameandresponseType. Multiple handlers may subscribe to the same combination of queryName/responseType. -
query
public <Q,R> CompletableFuture<QueryResponseMessage<R>> query(@Nonnull QueryMessage<Q, R> queryMessage) Description copied from interface:QueryBusDispatch 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. -
scatterGather
public <Q,R> Stream<QueryResponseMessage<R>> scatterGather(@Nonnull QueryMessage<Q, R> queryMessage, long timeout, @Nonnull TimeUnit timeUnit) Description copied from interface:QueryBusDispatch 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.- Specified by:
scatterGatherin interfaceQueryBus- Type Parameters:
Q- the payload type of the queryR- the response type of the query- Parameters:
queryMessage- the querytimeout- time to wait for resultstimeUnit- unit for the timeout- Returns:
- stream of query results
-
subscriptionQuery
@Deprecated public <Q,I, SubscriptionQueryResult<QueryResponseMessage<I>,U> SubscriptionQueryUpdateMessage<U>> subscriptionQuery(@Nonnull SubscriptionQueryMessage<Q, I, U> query, SubscriptionQueryBackpressure backPressure, int updateBufferSize) Deprecated.in favor of using the {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.
- Specified by:
subscriptionQueryin interfaceQueryBus- 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
public <Q,I, SubscriptionQueryResult<QueryResponseMessage<I>,U> SubscriptionQueryUpdateMessage<U>> subscriptionQuery(@Nonnull SubscriptionQueryMessage<Q, I, U> query, int updateBufferSize) Description copied from interface:QueryBusDispatch 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.
- Specified by:
subscriptionQueryin interfaceQueryBus- 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
Description copied from interface:QueryBusGets theQueryUpdateEmitterassociated with thisQueryBus.- Specified by:
queryUpdateEmitterin interfaceQueryBus- Returns:
- the associated
QueryUpdateEmitter
-
localSegment
Description copied from interface:DistributedReturn the message bus of typeMessageBuswhich is regarded as the local segment for this implementation. Would return the message bus used to dispatch and handle messages in a local environment to bridge the gap in a distributed set up.- Specified by:
localSegmentin interfaceDistributed<QueryBus>- Returns:
- a
MessageBuswhich is the local segment for this distributed message bus implementation
-
registerHandlerInterceptor
public Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super QueryMessage<?, ?>> interceptor) Description copied from interface:MessageHandlerInterceptorSupportRegister the givenhandlerInterceptor. After registration, the interceptor will be invoked for each handled Message on the messaging component that it was registered to, prior to invoking the message's handler.- Specified by:
registerHandlerInterceptorin interfaceMessageHandlerInterceptorSupport<QueryMessage<?,?>> - Parameters:
interceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
registerDispatchInterceptor
@Nonnull public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super QueryMessage<?, ?>> dispatchInterceptor) 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:
dispatchInterceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
disconnect
public void disconnect()Disconnect the query bus from Axon Server, by unsubscribing all known query handlers and aborting all queries in progress. -
shutdownDispatching
Shutdown the query bus asynchronously for dispatching queries to Axon Server. This process will wait for dispatched queries which have not received a response yet and will close off running subscription queries. This shutdown operation is performed in thePhase.OUTBOUND_QUERY_CONNECTORSphase.- Returns:
- a completable future which is resolved once all query dispatching activities are completed
-
subscriptionQuery(SubscriptionQueryMessage, int)}