CQRS and projections
An order-status read model built from six public topics: one guarded upsert per event, a view that says how current it is, a paused topic that leaves it visibly stale, and the same view built by a Camel route.
examples/16-cqrs-and-projections/ keeps one table, orders.order_view, built from the events of the order, payment and shipping services, and answers GET /orders/{id} and GET /customers/{customerId}/orders from it. It has no write model. It accompanies CQRS and projections.
It uses Quarkus, Hibernate ORM with Panache, Flyway, Quarkus REST, SmallRye Reactive Messaging with pausable channels, Camel Kafka for the comparison route, PostgreSQL, Kafka and OpenTelemetry to the LGTM stack.
(cd examples/domain-model && mvn -B -q install)
cd examples/16-cqrs-and-projections
mvn -B verify
./verify.sh
What to observe
- Each event moves one column. A payment sets the payment status and never the shipment; the status a reader sees is the furthest fact the row holds.
- A paused topic leaves the view stale, and the answer says so. The group has lag 1, reads return SHIPPED with an older
asOf, and after resume the order is DELIVERED. - A late status does not move the view back.
ShipmentInTransitapplied afterShipmentDeliveredleaves DELIVERED. - An event can arrive before its order. The row exists without a customer until
OrderPlacedis applied. - Replay is harmless. Resetting all six groups to the earliest offset leaves the view unchanged.
- One route builds the same view. A single Camel consumer over the six topics produces the same hash, through the same projector.
Infrastructure
Kafka, PostgreSQL and the LGTM stack from examples/_infra, a one-shot container that creates the six topics with one partition each, and order-service. There is no Connect and no registry. The compose project is edp-16.