Wire contract

The wire contract is the part of klok-common that is stated as data rather than as Java: one JSON file and six fixture files under src/main/resources/dev/klok/wire-contract/, published inside the jar and as the wire-contract zip classifier of dev.klok.framework:klok-common. It exists so that a broker client written in TypeScript, Python or any other language reproduces exactly what the Java client and the Quarkus extension put on the broker, without reading Java source.

File Content
klok-wire-contract-v1.json the klok-* property names, which side sets them, their formats, the legacy aliases and their policy; the derived MDC and CloudEvents extension forms; the CloudEvents binary-mode rules including dataschema; the topic naming rules, the companions of a topic and the topic provisioning rules with the TOPIC_MISSING and TOPIC_ACCESS_DENIED messages; the subscription, acknowledgement, dead letter and request/reply conventions; the metadata a client attaches to its consumers and producers; the three correlation ids, the order of the headers a global id is taken from and the transition from klok-correlation-id (correlation); the log field rule and the field table (logFields); the connection parameters (listener name, OAuth2, trusted CA with host name verification on, environment variables); the Avro wire schema rules
topic-naming-cases.json inputs and expected outputs of every topic naming rule, including taking a name apart (parseTopicName), the companions of a topic (companionTopics) and the cases that must fail
topic-provisioning-cases.json the klok.dev request link, the tenant's Pulsar file, the owner hint, the broker role of a client, and the full TOPIC_MISSING and TOPIC_ACCESS_DENIED messages
property-forms-cases.json inputs and expected outputs of mdcKey, cloudEventAttribute, logField, source, defaultType and dataSchemaUrn
correlation-cases.json the global id from each header source, names in any case, unusable values falling through to the next source, generated ids, the platform id of a consumed message and the value rule (fromHeaders, globalOrNew, platformFromMessage, usable)
service-logging-cases.json route id to solution id, leg id and direction; status and chain status values; the chain status rules; retry backoff; the log event topic
access-cases.json the roles each Keycloak group gives, the GitLab groups and projects of a tenant the platform manages, and the GitLab access level a person's roles give in each (Access roles and GitLab access)

dev.klok.framework.common.wire.KlokWireContract opens the files from the class path; it deliberately has no JSON dependency, so klok-common stays free of runtime dependencies.

Consumer and producer metadata

messaging.clientMetadata lists what a client attaches when it creates a consumer or a producer (Pulsar consumer and producer properties): every consumer carries klok-route-id, klok-instance and klok-subscription-concurrency (the receive loops it runs, a decimal integer), every producer klok-route-id and klok-instance. The broker shows them in the topic stats (subscriptions.<name>.consumers[].metadata, publishers[].metadata), which is how a tool that reads the broker, such as klok.dev's broker view, tells which route and instance a consumer or publisher belongs to and how many messages it handles at the same time, including a concurrency set from the deployment's environment that the project's source does not show. One pod is one consumer however high its concurrency. The Java constants are KlokClientMetadata. The reader of a topic is identified by its subscription name (the route id), never by the topic name (messaging.subscription.readerIdentity).

Request/reply

messaging.requestReply states how a synchronous call over the broker works in every client. The requester sends the request with klok-reqres-id (pairs the reply with the request) and klok-reply-topic (the shared response topic, ReqRes_<Req>_<Res>[_<purpose>]_Response), and listens on that topic with a reply subscription of its own, reply-subscriber-<clientId>-<uuid>:

  • The reply subscription is non-durable (replyConsumerSubscriptionMode). It lives exactly as long as its requester, so a stopped, redeployed or crashed process leaves nothing behind. A durable one outlived its process and went on collecting every reply to every requester; on 2026-10-06 the two ODL response topics carried 367 and 396 such subscriptions with 100–180 million messages of backlog (klok-brokerclient-java#10).
  • The request names its reply subscription in klok-reply-subscription (REPLY_SUBSCRIPTION), set by the client. The Python and Node Pulsar libraries cannot make a non-durable consumer, so those clients read replies with a reader, whose subscription the library names <prefix>-reader-<random>. Such a client uses reply-subscriber-<clientId>-<uuid> as the reader's subscription role prefix and sends that prefix.
  • The replier keys the reply with that value instead of the ordinary key (klok-corr-global), copies the property onto the reply, and batches replies by key (replyBatching), so that every entry on the broker holds replies to one subscription.
  • The broker delivers a reply only to the subscription it is keyed to. Every requester shares the response topic, so without help each live requester receives every reply. The entry filter klok-reply-subscription (klok/framework/klok-pulsar-entry-filter) rejects, per subscription, an entry whose key starts with reply-subscriber- and names another subscription: the subscription must be named by the key, or be a reader subscription <key>-reader-<random>. Anything else passes, so old and new clients mix in both directions: an old requester or an old replier simply gets the old fan-out.
  • A pending request is kept as long as its requester waits (pendingReplyLifetime): its reply timeout. Until 0.3.6 the contract said pendingReplyTtlMs: 30000, and the Java and Python clients kept every pending request for 30 seconds whatever its timeout, so a reply that took longer was lost to a requester waiting 120 seconds, which then answered its own caller with a timeout (klok-brokerclient-java#9). No client read the value, so it is gone.
  • The requester still pairs replies by klok-reqres-id. The filter is an optimisation, not the guarantee. A reply that is not pending is acknowledged without decoding its payload.

Correlation

correlation states the three correlation ids as data, so that a Python or TypeScript service takes, creates and passes them on exactly like a Java route. The rules themselves, and why there are three, are on Log fields and correlation:

  • ids: for the global, platform and service id, the property, the MDC key and the log field, what it groups, where it is taken from, when it is created and where it goes and never goes;
  • globalOrder: the headers a global id is taken from, in order, each with how its value is read (extract: as is, the trace id of a traceparent or a B3 header, the Root= of x-amzn-trace-id, the trace part of x-cloud-trace-context) and the klok-corr-global-source it gives; names are matched without regard to case;
  • valueRule: a value is usable when it has 1–128 characters of A-Z a-z 0-9 . _ : - / = + @, nothing is trimmed, and an unusable value falls through to the next source (unusableFallsThrough);
  • platformFromMessage: klok-corr-platform, then the transition names, on a consumed message only;
  • transition: how services before and after klok-common 0.4.0 keep one chain, and when it ends (klok-common#12).

properties.logOnly lists klok-corr-service and klok-corr-global-source, the two Klok context keys that are never a message property. During the transition the client writes klok-correlation-id itself, with the value of klok-corr-global (properties.setByClientRules). In Java, KlokCorrelation implements the section and runs correlation-cases.json.

Log fields

logFields states the field names of the three log record types in OpenSearch (transaction, event, console): the rule (a Klok context value is the property name with every - and . written as _, derivedForms.logField), the fields every type has, those of events and console lines, those of one type only, the levels (TRACE, DEBUG, INFO, WARN, ERROR) and the earlier names each one replaces (renamed). A log receiver, a console shipper or a reader such as klok.dev and klok logs takes its field names from here; the page with the reasons is Log fields and correlation.

Connection defaults

connection.env lists the environment variables of a client, each with its default. KLOK_BROKER_SERVICE_URL defaults to pulsar+ssl://broker.ipaas.se:6651, the stable name of the Klok broker rather than the name of one node, so a client keeps its address when the nodes behind the name change. connection.trustedCa turns host name verification on, so an address is only usable when the broker's certificate lists its name.

Topic provisioning

topics.provisioning states that topics on the Klok broker are provisioned from Git and never created automatically (autoCreate: false), while subscriptions are created by their consumer (subscriptionsAutoCreate: true); the reasons and the developer's view are on Naming conventions. For a client or a tool it holds everything needed to report a missing topic or grant in the same words as the Java client:

  • source: the repository, the tenant's Pulsar file (pulsar_tenant_<tenantFile>.yml, the tenant with - as _) and its keys topics, namespace_grants and topic_grants;
  • role: a client's broker role, service-account-<client id>;
  • request: the klok.dev link, <baseUrl>/monitoring/broker/request?topic=<topic>&access=<access>, with the base URL from KLOK_DEV_URL or https://klok.dev, the topic percent-encoded (RFC 3986 unreserved characters kept), and access create for a missing topic or the operation for a missing grant;
  • ownerHint: who approves, a TenantAdmin of the tenant or a DomainAdmin of the domain;
  • errors: TOPIC_MISSING and TOPIC_ACCESS_DENIED, both retryable: false and HTTP status 500 (a configuration fault of the service, not of its caller), the Pulsar errors each one stands for, and the message template as lines;
  • placeholders and rendering: what each {name} in a template is and how it is filled. Every value is taken from the topic name and the client's own configuration, never from a message.

topics.companions states which topics exist with a topic as rules a client applies without Java: match the simple name against endsWith and startsWith, first rule wins, and apply each append or replaceSuffix operation to the full name. It is data so that a tool that creates or checks topics, such as an Ansible role, klok.dev or a build task, applies exactly the same rule without Java.

In Java, KlokNamingConventions.companionTopics and dev.klok.framework.common.messaging.KlokTopicProvisioning implement both; KlokWireContractParityTest asserts the constants and templates against the file and also applies the companion rules as data to the contract's own examples.

How it is kept true

  • The Java constants are one implementation of the contract, not its source. KlokWireContractParityTest reflects over KlokMessageProperties, KlokClientMetadata, KlokCloudEventAttributes and KlokNamingConventions and fails the build when a constant and the file disagree, in either direction. KlokNamingConventionsFixtureTest, KlokCloudEventAttributesFixtureTest and KlokCorrelationFixtureTest run every case of the fixture files.
  • A client in another language carries a copy of the files of a klok-common release, kept with klok vendor: a source.json next to the files names the release and the sha256 of each file, klok vendor check fails when a copy differs from its release, and the job that builds or releases the client runs klok vendor sync --latest first, so what ships has the current contract. The copy's own tests run the same fixture cases (Vendored copies). The copies today: | Copy | Where | What a new contract can need | | --- | --- | --- | | TypeScript broker client | klok/framework/klok-brokerclient-java, typescript/klok-brokerclient-typescript/wire-contract/ | its tests run every method of topic-naming-cases.json, so companionTopics is implemented with the copy; the provisioning messages from topic-provisioning-cases.json; from 0.4.0 logField (property-forms-cases.json) and the correlation rules (correlation-cases.json) | | Python broker client | klok/framework/klok-brokerclient-java, python/klok-brokerclient-python/src/klok_brokerclient/wire_contract/ | the same as TypeScript | | klok.dev | klok/application/frontend-klok-dev, vendor/klok-wire-contract/ | lib/server/__tests__/topic-naming-contract.test.ts fails on a method it does not know, so companionTopics is added to lib/server/integration-context-topics.ts |

A Java tool, such as the Gradle plugin, depends on the klok-common jar instead of a copy and calls the Java implementation.

  • contractVersion changes only when a name or rule changes meaning. Adding a property, a case or a convention is a normal klok-common release; renaming one is a new contract version and a coordinated release of every client.

Service logging

serviceLogging states the invocation logging of the Quarkus extension as rules any language can follow, so that a Python or TypeScript worker shows up in OpenSearch exactly like a Java route:

  • every invocation logs START, optional PROGRESS, then exactly one FINISHED or FAILED; the numeric values (10000, 20000, 50000, 99000) make the highest one the current status;
  • ERROR and WARN are levels, not statuses: a retry is PROGRESS at ERROR level, a problem that does not stop the invocation is PROGRESS at WARN level, and neither changes the chain status. The levels are TRACE, DEBUG, INFO, WARN, ERROR; WARNING and FATAL are gone;
  • retries happen inside the invocation, and a failed invocation says how it ended in klok.disposition (DELIVERED, QUARANTINED, UNRESOLVED). How many, by the platform's principles of error handling:
    • a retryable failure gets retryDefaults: 5 retries, 1 s backoff doubling up to 60 s;
    • on a route that consumes from the broker, a failure that says try later (transientRetryDefaults.codes: UPSTREAM_UNAVAILABLE, UPSTREAM_TIMEOUT, BROKER_UNAVAILABLE) gets up to 20 with the same backoff, about 15 minutes, so that an outage of a target pauses a flow instead of draining it into its dead letter queue. A route or solution that sets its own number keeps it for every code. A client without error codes, such as the Python and TypeScript broker clients, retries every failure as retryDefaults says;
    • a route that answers its caller (syncRetries) does not retry unless it is configured to (syncRetryDefaults), so its caller gets the error instead of a timeout. A request that was sent and got no reply is never retried, since it may have run, and a configured retry above syncRetryLimits (3 retries, 2 s of backoff in total) is warned about when the route starts;
  • a NOT_FOUND that an invocation answering its caller (a REST handler, a request/reply service) delivered is an answer, not a failure (answeredNotFound): it logs FINISHED at INFO with klok.outcome=NOT_FOUND, klok.disposition=DELIVERED and the error text as its message (event.onAnsweredNotFound), so its chain finishes. Every other failure, and a NOT_FOUND that was propagated or could not be delivered, logs FAILED. Until 2026-10 every 4XX was FAILED, and a client that read something not stored yet turned into failed chains that klok.dev's error analysis analysed;
  • the direction comes from the leg letter of the route id (I/T IN, P PROCESSING, E OUT, A API, S SUB); inbound invocations (IN, API) count separately in the chain status;
  • each entry is a log line and a KlokLogEventV6 (dev.klok.klok.datamodel:klok-log-event-v6) on persistent://<tenant>[_<env>]/common/KlokLogEventV6[_<purpose>], keyed with the global id and sent without ever blocking the invocation. event.fields says which context property fills which V6 field: the three correlation ids, the invocation ids, the leg and direction under context, retries and the end of a failure under outcome, the pod under process, the route's own klok.<name> values under fields. A failed invocation whose message went to the dead letter topic names the copy in outcome.quarantineRef (<dead letter topic>#<message id>). The receivers store every value under its logFields name (klok_corr_global, kubernetes.pod_name, klok_file_name);
  • an entry says where it ran and what it belongs to outside Klok: a process in Kubernetes names its pod (process.podName, process.namespaceName), and an invocation whose input arrived with a W3C traceparent header names the trace and the caller's span (context.traceId, context.spanId);
  • in a cluster a service writes its console as JSON, one object per line, with the text as message, the level as log_level and every MDC and configured context value under its logFields name (consoleLine.cluster); the shipper stores the object as it is. In dev mode and tests (%dev, %test) it writes readable text with six brackets in a fixed order (consoleLine.devAndTest): route id, global id, status, invocation id, task id, trace id. Services built before klok-common 0.4.0 write those brackets in the cluster too, with klok-correlation-id in the second, which the shipper stores as both klok_corr_global and klok_corr_platform (consoleLine.legacy).

The Python and TypeScript broker clients write neither the pod nor the trace (klok-brokerclient-java#41).

The chain status is derived by the log receivers (klok-egress-opensearch), never sent. The Java implementation is in the Quarkus extension (KlokServiceStatus, KlokChainStatus, KlokRouteIdentity, KlokLeg, KlokLogEventMapper, KlokRetryPolicy); KlokServiceLoggingContractTest here checks that the cases follow the rules of the contract.

What is not in the contract

Everything a client needs is in the file; everything else in klok-common is Java tooling and stays Java only: KlokFastID (any UUID is a valid id on the wire), KlokGenericTypeResolver, KlokSymmetricEncryption, KlokDateHelper, JvmHelper, and the repository and package naming (repoName, projectPackageName, DomainType, ProjectType). The documentation naming (repository path to doc id) is not in klok-common at all; its ports share their own fixture file (Naming conventions). The OpenTelemetry meter names of the Java broker client and its MDC handling are Java implementation details as well.

Datamodel identity on the wire

ce-dataschema names the datamodel version a payload was produced with: urn:klok:schema:<docId>:<Record>:<artifactVersion>, for example urn:klok:schema:klok-datamodel-common-klokodl-v1:KlokOdlSearchV1:1.0.0-build.260910131202. <docId> is the documentation id of the datamodel project, so the URN resolves to https://docs.klok.dev/<docId>/schemas/<Record>.avsc and to the schemas zip classifier of the datamodel's Maven artifact. KlokCloudEventAttributes.dataSchemaUrn builds it; the publisher in the Quarkus extension reads the parts from the datamodel jar's metadata and omits the attribute for payloads that carry none.

The Avro schema on the wire is the schema the datamodel pipeline derives from the XSD. Java embeds it in the generated class, and the TypeScript and Python datamodel packages ship the same .avsc next to their generated types. Until a datamodel has been re-released that way, Java registers a schema derived by reflection from the generated class, which is a different Avro type; the broker client documentation ("Publishing from TypeScript") records the measured consequences and the avro.transition entry of the contract points at it.