liveBook · Manning

Query bus

As explained in Clean Applications with Hexagonal Architecture

A query bus dispatches query requests to their corresponding handlers through a single entry point.

When adapters depend directly on query handlers, adding or changing a read path can spread wiring changes outward. A query bus gives adapters one entry point: they submit a query, and the bus resolves its handler at runtime. section 4.6.2 section 4.8

Listing 4.19 QueryBus from the Architecture Kernel
public interface QueryBus {
  <E, R, Q extends Query> Either<E, R> 
    query(final Q query); #A
}

The generic contract accepts a query and returns an Either containing either an error or a result. section 4.6.2

A REST controller can validate a GetArticleByIdQuery, pass it to QueryBus, and map the returned ArticleDTO to an HTTP response. The handler fetches through a repository and maps the result to the DTO; the adapter need not know the handler class. section 4.6.3

In a Spring assembly, the bus is wired against Spring's ApplicationContext. Adding a use case means adding a handler, without changing adapter code or wiring updates. section 4.8 section 6.6

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Defines a generic query contract and runtime handler resolution, while leaving registry mechanics to the assembly.
Examples
Routes GetArticleByIdQuery from a REST controller to a handler returning ArticleDTO.
What you can do after
Apply it via QueryBus to dispatch validated queries from adapters and receive explicit Either outcomes.
How it connects
Pairs with QueryHandler, CQS, command buses, and DTO projections.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.