public interface QueryBus
QueryMessage.getQueryName()
and
QueryMessage.getResponseType()
on the query bus. There may be multiple handlers for each combination of
queryName/responseName.Modifier and Type | Method and Description |
---|---|
<Q,R> CompletableFuture<QueryResponseMessage<R>> |
query(QueryMessage<Q,R> query)
Dispatch the given
query to a single QueryHandler subscribed to the given query 's queryName
and responseType. |
<Q,R> Stream<QueryResponseMessage<R>> |
scatterGather(QueryMessage<Q,R> query,
long timeout,
TimeUnit unit)
Dispatch the given
query to all QueryHandlers subscribed to the given query 's queryName/responseName. |
<R> Registration |
subscribe(String queryName,
Type responseType,
MessageHandler<? super QueryMessage<?,R>> handler)
Subscribe the given
handler to queries with the given queryName and responseName . |
<R> Registration subscribe(String queryName, Type responseType, MessageHandler<? super QueryMessage<?,R>> handler)
handler
to queries with the given queryName
and responseName
.
Multiple handlers may subscribe to the same combination of queryName/responseName.queryName
- the name of the query request to subscriberesponseType
- the type of response the subscribed component answers withhandler
- a handler that implements the query<Q,R> CompletableFuture<QueryResponseMessage<R>> query(QueryMessage<Q,R> query)
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
.
Q
- the payload type of the queryR
- the response type of the queryquery
- the query<Q,R> Stream<QueryResponseMessage<R>> scatterGather(QueryMessage<Q,R> query, long timeout, TimeUnit unit)
query
to all QueryHandlers subscribed to the given query
's queryName/responseName.
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.
Q
- the payload type of the queryR
- the response type of the queryquery
- the querytimeout
- time to wait for resultsunit
- unit for the timeoutCopyright © 2010–2018. All rights reserved.