public class SimpleQueryBus extends Object implements QueryBus
In case multiple handlers are registered for the same query and response type, the query(QueryMessage)
method will invoke one of these handlers. Which one is unspecified.
Constructor and Description |
---|
SimpleQueryBus()
Initialize the query bus without monitoring on messages and a
LoggingQueryInvocationErrorHandler . |
SimpleQueryBus(MessageMonitor<? super QueryMessage<?,?>> messageMonitor,
TransactionManager transactionManager,
QueryInvocationErrorHandler errorHandler)
Initialize the query bus with the given
messageMonitor and given errorHandler . |
SimpleQueryBus(TransactionManager transactionManager)
Initialize the query bus using given
transactionManager to manage transactions around query execution
with. |
Modifier and Type | Method and Description |
---|---|
protected Map<org.axonframework.queryhandling.SimpleQueryBus.QueryDefinition,Collection<MessageHandler<? super QueryMessage<?,?>>>> |
getSubscriptions()
Returns the subscriptions for this query bus.
|
<Q,R> CompletableFuture<R> |
query(QueryMessage<Q,R> query)
Dispatch the given
query to all QueryHandlers subscribed to the given query 's queryName/responseName. |
<Q,R> Stream<R> |
queryAll(QueryMessage<Q,R> query,
long timeout,
TimeUnit unit)
Dispatch the given
query to all QueryHandlers subscribed to the given query 's queryName/responseName. |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<QueryMessage<?,?>> interceptor)
Registers an interceptor that intercepts Queries as they are sent.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<QueryMessage<?,?>> interceptor)
Registers an interceptor that is used to intercept Queries before they are passed to their
respective handlers.
|
<R> Registration |
subscribe(String queryName,
Class<R> responseType,
MessageHandler<? super QueryMessage<?,R>> handler)
Subscribe the given
handler to queries with the given queryName and responseName . |
public SimpleQueryBus()
LoggingQueryInvocationErrorHandler
.public SimpleQueryBus(TransactionManager transactionManager)
transactionManager
to manage transactions around query execution
with. No monitoring is applied to messages and a LoggingQueryInvocationErrorHandler
is used
to log errors on handlers during a scatter-gather query.transactionManager
- The transaction manager to manage transactions around query execution withpublic SimpleQueryBus(MessageMonitor<? super QueryMessage<?,?>> messageMonitor, TransactionManager transactionManager, QueryInvocationErrorHandler errorHandler)
messageMonitor
and given errorHandler
.messageMonitor
- The message monitor notified for incoming messages and their resulttransactionManager
- The transaction manager to manage transactions around query execution witherrorHandler
- The error handler to invoke when query handler report an errorpublic <R> Registration subscribe(String queryName, Class<R> responseType, MessageHandler<? super QueryMessage<?,R>> handler)
QueryBus
handler
to queries with the given queryName
and responseName
.
Multiple handlers may subscribe to the same combination of queryName/responseName.public <Q,R> CompletableFuture<R> query(QueryMessage<Q,R> query)
QueryBus
query
to all QueryHandlers subscribed to the given query
's queryName/responseName.
Completes on the first result. It is up to the QueryBus implementor to decide what the definition of first result is.
When no handlers are available that can answer the query, the returned CompletableFuture will be completed with
a NoHandlerForQueryException
.
public <Q,R> Stream<R> queryAll(QueryMessage<Q,R> query, long timeout, TimeUnit unit)
QueryBus
query
to all QueryHandlers subscribed to the given query
's queryName/responseName.
Returns a stream of results which completes if 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.
protected Map<org.axonframework.queryhandling.SimpleQueryBus.QueryDefinition,Collection<MessageHandler<? super QueryMessage<?,?>>>> getSubscriptions()
public Registration registerHandlerInterceptor(MessageHandlerInterceptor<QueryMessage<?,?>> interceptor)
interceptor
- the interceptor to invoke before passing a Query to the handlerpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<QueryMessage<?,?>> interceptor)
interceptor
- the interceptor to invoke when sending a QueryCopyright © 2010–2017. All rights reserved.