klok-brokerclient-java (dev.klok.framework:klok-brokerclient-java) is the typed wrapper around the Apache Pulsar
client that every Klok integration and platform service uses to publish, subscribe and do request/reply on the broker.
The Quarkus extension builds on it. A Python client in the same repository (klok-brokerclient, see Python client and
workers) puts the same bytes and properties on the broker, so Python workers take part in the same
chains; the TypeScript client (@klok-integration/brokerclient, see TypeScript client) does the
same for Node processes, such as a web backend, a worker or a command line tool.
What the client adds on top of Pulsar:
- Typed messages. A
KlokBrokerClient<T>publishes and consumes one datamodel class with the Avro schema generated from the datamodel project. - Bytes for high throughput. A
KlokBytesBrokerClientis the same client withbyte[]payloads that go on the wire untouched, for services that bring their own encoding and cannot spend the Avro serialization on every message (see Bytes client). - Naming. Topic names come from
KlokNamingConventionsin klok-common, so a publisher and a subscriber that name the same datamodel and purpose meet on the same full topic (persistent://<tenant>[_<env>]/<domain>/<Model>). - Context properties. The client stamps
klok-instance,klok-sent-timeandklok-body-typeon every message and carries whatever else the caller gives: the chain context (klok-corr-global,klok-corr-platform,klok-invocation-id,klok-task-id,klok-route-id, ...) and the CloudEventsce-*attributes, which the Quarkus extension sets for every route. Readers get them as typed getters onKlokBrokerMessage(see Properties and CloudEvents). The Python and TypeScript clients derive the context themselves, from the message a handler received. - Request/reply.
KlokBrokerClientSync<T, U>implements theReqRes_<Req>_<Res>_Request/_Responsetopic pair with a reply id, a reply topic and a timeout, on a non-durable reply subscription that the request names inklok-reply-subscriptionand the replier keys the reply with. - Authentication. OAuth2 client credentials against Keycloak, exchanged for the Pulsar token by the Pulsar client.
- Missing topics and grants say what to do. Topics on the Klok broker are never created automatically. A topic that is
missing, or a grant the service's role lacks, fails at once with
KlokTopicMissingExceptionorKlokTopicAccessDeniedException, whose message names the topic, the klok.dev request link, who approves it and the line to add to the tenant's Pulsar file;verifyPublishandverifyConsumecheck a topic at startup (see Missing topics and grants). The Python and TypeScript clients report the same with the same words. - A lost connection is loud. A watchdog checks every producer and consumer, logs one that stays disconnected at ERROR
as
KLOK_BROKER_CONNECTIONon every check, creates producers and reply consumers again, and reports what it sees inKlokConnectionHealthfor a health check (see Connection health). - Nothing a handler throws ends a consumer. An
Errorfails its message like an exception does, and the receive loop goes on. A fatal one, such as anOutOfMemoryError, and a loop that ends for any other reason are reported inKlokSubscriptionHealth(see An Error in a handler on Authentication and subscriptions). - Observability. MDC propagation of the context ids and OpenTelemetry metrics per route.
- A claim check store. A payload too large for a message goes to the platform's object storage (RustFS) with the keys
and
klokcc://references of the extension's claim check, in Java and TypeScript (see Claim check).