Topics, Subscriptions And The Broker
Klok has one central broker, Apache Pulsar, and every system talks to it instead of to each other. This page gives the words Klok uses for it and the one idea that ties them together: the topic stores the messages, and the subscription decides how they are read. Other pages say how a topic comes into existence (Topics On The Klok Broker), how it is named (Topic And Naming Cheatsheet) and how fast it is (Broker Throughput And Capacity).
The Words
| Word | What it is |
|---|---|
| The broker | The platform's Pulsar service as a whole, its storage included. Routes publish to it and consume from it; systems never call each other. |
| Topic | A named, persisted, ordered log of messages: persistent://<tenant>[_<env>]/<domain>/<Model>[_<purpose>]. It carries one datamodel, belongs to the publisher's tenant and keeps its messages after they are read. |
| Message | One entry on a topic: a CloudEvent whose data is the datamodel. It is an event when it states that something happened, a request or a reply on a request/reply pair. |
| Subscription | A reader's named position on a topic, named after the reading route's id (ACM012E1_DeliveryNotice). The broker remembers per subscription which messages are acknowledged. |
| Subscription type | How the readers of one subscription share its messages: as a stream or as a queue (below). |
| Publish, consume | The two broker rights. A tenant publishes only in its own namespaces; reading another tenant's topic is a consume grant on that topic. |
| Request/reply | A pair of topics, ReqRes_<Request>_<Reply>_Request and _Response, for a caller that needs an answer. |
| Dead letter topic (DLQ) | <topic>_DLQ, provisioned with every topic. The framework republishes a message there when its retries are spent or it can never succeed. |
Klok does not call the broker a mesh, a bus or a hub. A service mesh and an event mesh are other things (a network of sidecars, a network of brokers), and a bus suggests logic in the middle. Logic lives in the routes; the broker stores and delivers.
Stream Or Queue: The Subscription Decides
Two traditions meet in Pulsar. In Kafka a topic is a log that readers stream through in order. In ActiveMQ and other JMS brokers a queue hands each message to one of several competing consumers, and a topic is something else. Pulsar keeps one kind of topic, always a persisted log, and lets each subscription choose how it is read:
| Subscription type | Reads the topic as | Order | Use it when |
|---|---|---|---|
exclusive (Klok's default) |
a stream | strict, one consumer at a time | the order of the topic matters, which is the default expectation of an integration |
failover |
a stream with a standby | strict; a second consumer takes over if the first goes away | as exclusive, with a hot standby |
shared |
a queue | given up; each message goes to one of the competing consumers | throughput matters more than order, and several pods share the work |
key_shared |
a stream per key | strict within a message key, parallel across keys | an entity's events must stay in order (an order id, a customer id) but the topic as a whole may run in parallel |
A route sets it with <RouteId>.subscription.type. A concurrency above one makes an exclusive subscription shared,
because messages handled side by side are no longer in order; key_shared keeps the order per key. Running a second
replica of a consuming service needs shared or key_shared, since an exclusive subscription lets only one pod
consume. The keys are described in the configuration reference of klok docs read klok-framework-klok-quarkus-extension.
One Topic, Many Readers
Every subscription on a topic receives every message. That is publish/subscribe: the publisher writes once, and each consuming route reads at its own pace through its own subscription. Within a subscription the type decides whether the readers take turns (a queue) or one reads in order (a stream).
┌── subscription KLK010E1_... (exclusive) ──► one egress, in order
publisher ──► topic ─────┼── subscription KLK010P1_... (shared) ──► three pods, competing
└── subscription ACM012E1_... (key_shared) ─► order per key
Because a reader is its subscription, a new consumer never changes the topic or the publisher. It needs only a consume
grant and its own subscription, which the consuming route creates when it starts.
How To Say It
| Write | Not |
|---|---|
| The onramp publishes the invoice on the broker. | The onramp sends the invoice into the mesh. |
| Ingress: external system → topic. Processing: topic → topic. Egress: topic → external system. | Ingress: system → mesh. |
The egress consumes InvoiceV1_created through its subscription KLK007E1_.... |
The egress listens to the invoice queue. |
Set the subscription to shared to let three pods share the work. |
Make the topic a queue. |
The message went to the dead letter topic InvoiceV1_DLQ. |
The message went to the DLQ queue. |