Interface QueryGateway
- All Superinterfaces:
HasLocalHandlers
- All Known Implementing Classes:
DefaultQueryGateway
Gateway interface for dispatching queries and receiving responses in Flux Capacitor.
The QueryGateway
provides a high-level API for submitting queries and retrieving
results, either asynchronously or synchronously. It supports rich metadata and integrates with
both local and remote query handlers.
Queries can be sent as raw payloads, Message
objects, or Request
wrappers for typed responses.
This interface also supports registration of local handlers via HasLocalHandlers.registerHandler(Object)
.
For message types that are queries, the MessageType.QUERY
enum is typically used.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Gracefully shuts down this gateway and releases any held resources.<R> CompletableFuture
<R> Sends a typedRequest
query and returns a future representing the result.<R> CompletableFuture
<R> Sends a typedRequest
query with additional metadata and returns a future with the result.<R> CompletableFuture
<R> Sends the given query asynchronously and returns a future representing the result.<R> List
<CompletableFuture<R>> Sends multiple queries asynchronously and returns a list of futures, one for each result.<R> CompletableFuture
<R> Sends the given query along with metadata asynchronously and returns a future representing the result.<R> R
sendAndWait
(Request<R> query) Sends a typedRequest
query and waits for the result.<R> R
sendAndWait
(Request<R> payload, Metadata metadata) Sends a typedRequest
query with metadata and waits for the result.<R> R
sendAndWait
(Object query) Sends the given query and waits for the result, blocking the current thread.<R> R
sendAndWait
(Object payload, Metadata metadata) Sends the given query and metadata, then waits for the result.sendForMessage
(Message message) Sends the givenMessage
and returns a future representing the resulting message.sendForMessages
(Message... messages) Sends multiple queryMessage
s and returns a list of futures for the raw responses.Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.HasLocalHandlers
hasLocalHandlers, registerHandler, registerHandler, setSelfHandlerFilter
-
Method Details
-
send
Sends the given query asynchronously and returns a future representing the result.If the query is a
Message
, it is dispatched as-is. Otherwise, it is wrapped in a new message.- Type Parameters:
R
- the expected type of the result- Parameters:
query
- the query object- Returns:
- a
CompletableFuture
with the result
-
send
Sends the given query along with metadata asynchronously and returns a future representing the result.- Type Parameters:
R
- the expected result type- Parameters:
payload
- the query payloadmetadata
- additional metadata to attach to the message- Returns:
- a
CompletableFuture
containing the query result
-
sendForMessage
Sends the givenMessage
and returns a future representing the resulting message. This method gives access to the fullMessage
returned by the query handler.- Parameters:
message
- the message representing the query- Returns:
- a
CompletableFuture
with the response message
-
send
Sends multiple queries asynchronously and returns a list of futures, one for each result.- Type Parameters:
R
- the expected result type for each query- Parameters:
messages
- one or more query objects or messages- Returns:
- a list of
CompletableFuture
s for each query result
-
sendForMessages
Sends multiple queryMessage
s and returns a list of futures for the raw responses.- Parameters:
messages
- one or more messages representing queries- Returns:
- a list of
CompletableFuture
s containing the result messages
-
sendAndWait
Sends the given query and waits for the result, blocking the current thread.- Type Parameters:
R
- the expected result type- Parameters:
query
- the query object- Returns:
- the result of the query
-
sendAndWait
Sends the given query and metadata, then waits for the result.- Type Parameters:
R
- the expected result type- Parameters:
payload
- the query payloadmetadata
- additional metadata to attach to the query- Returns:
- the result of the query
-
send
Sends a typedRequest
query and returns a future representing the result.- Type Parameters:
R
- the expected result type- Parameters:
query
- theRequest
query- Returns:
- a
CompletableFuture
containing the result
-
send
Sends a typedRequest
query with additional metadata and returns a future with the result.- Type Parameters:
R
- the expected result type- Parameters:
payload
- theRequest
payloadmetadata
- metadata to attach to the request- Returns:
- a
CompletableFuture
with the result
-
sendAndWait
Sends a typedRequest
query and waits for the result.- Type Parameters:
R
- the expected result type- Parameters:
query
- theRequest
query- Returns:
- the result of the query
-
sendAndWait
Sends a typedRequest
query with metadata and waits for the result.- Type Parameters:
R
- the expected result type- Parameters:
payload
- theRequest
payloadmetadata
- additional metadata to attach to the query- Returns:
- the result of the query
-
close
void close()Gracefully shuts down this gateway and releases any held resources.
-