public class AxonServerQueryBus extends Object implements QueryBus
QueryBus
implementation that connects to Axon Server to submit and receive queries and query responses.
Delegates incoming queries to the provided localSegment
.Constructor and Description |
---|
AxonServerQueryBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
QueryUpdateEmitter updateEmitter,
QueryBus localSegment,
Serializer messageSerializer,
Serializer genericSerializer,
QueryPriorityCalculator priorityCalculator)
Creates an instance of the Axon Server
QueryBus client. |
Modifier and Type | Method and Description |
---|---|
void |
disconnect() |
QueryBus |
localSegment()
Returns the local segment configured for this instance.
|
void |
on(QueryProviderInbound.RequestCase requestCase,
Consumer<QueryProviderInbound> consumer) |
<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. |
<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,
SubscriptionQueryBackpressure backPressure,
int updateBufferSize)
Dispatch the given
query to a single QueryHandler subscribed to the given query 's
queryName/initialResponseType/updateResponseType. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
subscriptionQuery
public AxonServerQueryBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, QueryUpdateEmitter updateEmitter, QueryBus localSegment, Serializer messageSerializer, Serializer genericSerializer, QueryPriorityCalculator priorityCalculator)
QueryBus
client. Will connect to an Axon Server instance to submit
and receive queries and query responses.axonServerConnectionManager
- a AxonServerConnectionManager
which creates the connection to an Axon
Server platformconfiguration
- the AxonServerConfiguration
containing specifics like the client and
component names used to identify the application in Axon Server among othersupdateEmitter
- the QueryUpdateEmitter
used to emits incremental updates to
subscription querieslocalSegment
- a QueryBus
handling the incoming queries for the local applicationmessageSerializer
- a Serializer
used to de-/serialize the payload and metadata of query
messages and responsesgenericSerializer
- a Serializer
used for communication of other objects than query
message and response, payload and metadatapriorityCalculator
- a QueryPriorityCalculator
calculating the request priority based on
the content, and adds this priority to the requestpublic <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 timeoutpublic void disconnect()
public QueryBus localSegment()
public void on(QueryProviderInbound.RequestCase requestCase, Consumer<QueryProviderInbound> consumer)
public <Q,I,U> SubscriptionQueryResult<QueryResponseMessage<I>,SubscriptionQueryUpdateMessage<U>> subscriptionQuery(SubscriptionQueryMessage<Q,I,U> query, SubscriptionQueryBackpressure backPressure, 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.
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 QueryUpdateEmitter queryUpdateEmitter()
QueryBus
QueryUpdateEmitter
associated with this QueryBus
.queryUpdateEmitter
in interface QueryBus
QueryUpdateEmitter
public 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 registerCopyright © 2010–2019. All rights reserved.