public class AxonServerQueryBus extends Object implements QueryBus, Distributed<QueryBus>
QueryBus
implementation that connects to Axon Server to submit and receive queries and query responses.
Delegates incoming queries to the provided localSegment
.Modifier and Type | Class and Description |
---|---|
static class |
AxonServerQueryBus.Builder
Builder class to instantiate an
AxonServerQueryBus . |
Constructor and Description |
---|
AxonServerQueryBus(AxonServerQueryBus.Builder builder)
Instantiate a
AxonServerQueryBus based on the fields contained in the AxonServerQueryBus.Builder . |
Modifier and Type | Method and Description |
---|---|
static AxonServerQueryBus.Builder |
builder()
Instantiate a Builder to be able to create an
AxonServerQueryBus . |
void |
disconnect()
Disconnect the query bus from Axon Server, by unsubscribing all known query handlers.
|
QueryBus |
localSegment()
Return the message bus of type
MessageBus which is regarded as the local segment for this implementation. |
<Q,R> CompletableFuture<QueryResponseMessage<R>> |
query(QueryMessage<Q,R> queryMessage)
Dispatch the given
query to a single QueryHandler subscribed to the given query 's queryName and
responseType. |
QueryUpdateEmitter |
queryUpdateEmitter()
Gets the
QueryUpdateEmitter associated with this QueryBus . |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super QueryMessage<?,?>> dispatchInterceptor)
Register the given DispatchInterceptor.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super QueryMessage<?,?>> interceptor)
Register the given
handlerInterceptor . |
<Q,R> Stream<QueryResponseMessage<R>> |
scatterGather(QueryMessage<Q,R> queryMessage,
long timeout,
TimeUnit timeUnit)
Dispatch the given
query to all QueryHandlers subscribed to the given query 's
queryName/responseType. |
CompletableFuture<Void> |
shutdownDispatching()
Shutdown the query bus asynchronously for dispatching queries to Axon Server.
|
void |
start()
Start the Axon Server
QueryBus implementation. |
<R> Registration |
subscribe(String queryName,
Type responseType,
MessageHandler<? super QueryMessage<?,R>> handler)
Subscribe the given
handler to queries with the given queryName and responseType . |
<Q,I,U> SubscriptionQueryResult<QueryResponseMessage<I>,SubscriptionQueryUpdateMessage<U>> |
subscriptionQuery(SubscriptionQueryMessage<Q,I,U> query,
int updateBufferSize)
Dispatch the given
query to a single QueryHandler subscribed to the given query 's
queryName/initialResponseType/updateResponseType. |
<Q,I,U> SubscriptionQueryResult<QueryResponseMessage<I>,SubscriptionQueryUpdateMessage<U>> |
subscriptionQuery(SubscriptionQueryMessage<Q,I,U> query,
SubscriptionQueryBackpressure backPressure,
int updateBufferSize)
Deprecated.
in favor of using the {
subscriptionQuery(SubscriptionQueryMessage, int) } |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
subscriptionQuery
public AxonServerQueryBus(AxonServerQueryBus.Builder builder)
AxonServerQueryBus
based on the fields contained in the AxonServerQueryBus.Builder
.builder
- the AxonServerQueryBus.Builder
used to instantiate a AxonServerQueryBus
instancepublic static AxonServerQueryBus.Builder builder()
AxonServerQueryBus
.
The QueryPriorityCalculator
is defaulted to QueryPriorityCalculator.defaultQueryPriorityCalculator()
and the TargetContextResolver
defaults to a lambda returning the AxonServerConfiguration.getContext()
as the context. The ExecutorServiceBuilder
defaults to ExecutorServiceBuilder.defaultQueryExecutorServiceBuilder()
. The AxonServerConnectionManager
, the AxonServerConfiguration
, the local QueryBus
, the QueryUpdateEmitter
, and the message and generic
Serializer
s are hard requirements and as such should be provided.
AxonServerQueryBus
@StartHandler(phase=536870911) public void start()
QueryBus
implementation.public <R> Registration subscribe(String queryName, Type responseType, MessageHandler<? super QueryMessage<?,R>> handler)
QueryBus
handler
to queries with the given queryName
and responseType
.
Multiple handlers may subscribe to the same combination of queryName/responseType.public <Q,R> CompletableFuture<QueryResponseMessage<R>> query(QueryMessage<Q,R> queryMessage)
QueryBus
query
to a single QueryHandler subscribed to the given query
'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 a NoHandlerForQueryException
.
public <Q,R> Stream<QueryResponseMessage<R>> scatterGather(QueryMessage<Q,R> queryMessage, long timeout, TimeUnit timeUnit)
QueryBus
query
to all QueryHandlers subscribed to the given query
'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 the timeout
has expired, awaiting additional data to include in the stream.
scatterGather
in interface QueryBus
Q
- the payload type of the queryR
- the response type of the queryqueryMessage
- the querytimeout
- time to wait for resultstimeUnit
- unit for the timeout@Deprecated public <Q,I,U> SubscriptionQueryResult<QueryResponseMessage<I>,SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q,I,U> query, SubscriptionQueryBackpressure backPressure, int updateBufferSize)
subscriptionQuery(SubscriptionQueryMessage, int)
}query
to a single QueryHandler subscribed to the given query
'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.
subscriptionQuery
in interface QueryBus
Q
- the payload type of the queryI
- the response type of the queryU
- the incremental response types of the queryquery
- the querybackPressure
- the backpressure mechanism to be used for emitting updatesupdateBufferSize
- the size of buffer which accumulates updates before subscription to the flux
is
madepublic <Q,I,U> SubscriptionQueryResult<QueryResponseMessage<I>,SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q,I,U> query, int updateBufferSize)
QueryBus
query
to a single QueryHandler subscribed to the given query
'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.
subscriptionQuery
in interface QueryBus
Q
- the payload type of the queryI
- the response type of the queryU
- the incremental response types of the queryquery
- the queryupdateBufferSize
- the size of buffer which accumulates updates before subscription to the flux
is
madepublic QueryUpdateEmitter queryUpdateEmitter()
QueryBus
QueryUpdateEmitter
associated with this QueryBus
.queryUpdateEmitter
in interface QueryBus
QueryUpdateEmitter
public QueryBus localSegment()
Distributed
MessageBus
which 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.localSegment
in interface Distributed<QueryBus>
MessageBus
which is the local segment for this distributed message bus implementationpublic Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super QueryMessage<?,?>> interceptor)
MessageHandlerInterceptorSupport
handlerInterceptor
. 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.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<QueryMessage<?,?>>
interceptor
- The interceptor to registerpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super QueryMessage<?,?>> dispatchInterceptor)
MessageDispatchInterceptorSupport
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<QueryMessage<?,?>>
dispatchInterceptor
- The interceptor to register@ShutdownHandler(phase=536870911) public void disconnect()
Phase.INBOUND_QUERY_CONNECTOR
phase.@ShutdownHandler(phase=0) public CompletableFuture<Void> shutdownDispatching()
Phase.OUTBOUND_QUERY_CONNECTORS
phase.Copyright © 2010–2022. All rights reserved.