Queries

Commands are messages that express the request for data. Any application can declare it’s able to handle a query message and provide a response to it.

Query handling is fully async-native, with all query dispatching operations returning CompletableFuture or Publisher types. Query handlers can return these types directly, allowing for efficient asynchronous processing. Queries are routed based on the query’s MessageType (qualified name and version), independent of the Java class used to represent the query payload.

Types of queries

There are multiple types of queries that can be distinguished:

  1. Point-to-point queries: These are routed to a single handler, which is expected to return a single result. This is the most common type of query.

  2. Subscription queries: These request an initial result and then continue to receive updates as long as the subscription is active. The initial result and updates are combined in a single Publisher stream.

  3. Streaming queries: These queries are used to request a stream of results as a Publisher, which are returned as they become available. This is ideal for large result sets.

You can find more about each type of query in the Query dispatchers section.

Subsections

A summary of the various sections is given below.

Subsection Purpose

Handling

How to write and register query handlers

Dispatching

How to dispatch queries from your application code

Infrastructure

Query bus implementations and other query infrastructure components

Configuration

Configuration concerns for Query Messages using the Axon Framework