Guides by role

Three kinds of people touch klok-common. Most never open this repository: they meet its names in a route, a log line or an error message, and this page tells them where those come from and what to do.

For an integration developer

You build routes on the Klok Quarkus extension. You never add klok-common yourself: the extension declares it as an api dependency, so your service runs the version the extension was built against, and refreshing the catalog copy with ./gradlew updateKlokLibsToml brings a newer extension and with it a newer klok-common. What you meet:

  1. Topic names. A route never spells a topic. The extension derives it from the route's datamodel class and the purpose you configure (<RouteId>.topic.purpose or the route's topicPurpose()), through KlokNamingConventions: CustomerV1 with purpose created in domain finance of tenant acme is persistent://acme/finance/CustomerV1_created in production and persistent://acme_test/finance/CustomerV1_created in test. ./gradlew klokTopics lists every topic your project uses. The rules, including why the purpose is the publisher's and the reader is its subscription, are on Naming conventions.
  2. Context in every log line. The klok-* properties travel with every message and HTTP call your routes handle. In your service's log lines they appear as MDC keys with a dot (klok.corr-global, klok.route-id) and in OpenSearch as fields with underscores (klok_corr_global, klok_route_id); following one global id shows a whole business call across services. See Log fields and correlation and Message properties and CloudEvents.
  3. A missing topic or grant. Topics are provisioned from Git, never created by the broker. When one of yours is not, the deploy's klokTopicCheck and the service's start fail with TOPIC_MISSING or TOPIC_ACCESS_DENIED and a message that names the topic, your broker role, the klok.dev request link and the exact line to add by hand. Do what it says; request only the topic itself, never its _DLQ or _Response, which come with it. See When a topic or a grant is missing.
  4. Your own documentation. Mark a class that several routes depend on with @KlokDocs so that it gets its own generated page and the routes that use it get its source (The @KlokDocs annotation).
  5. Prompts for Kloker. A service that writes system prompts reads the shared platform knowledge with KlokKnowledge.get("platform-rules") instead of restating it (Klok knowledge).

If you need a topic name in your own code, for example in a custom route, call KlokNamingConventions; never build the string by hand.

For a developer of a client or a tool

You write something that talks to the Klok broker or reasons about its topics outside the Quarkus extension: a broker client in another language, a worker in Python or TypeScript, klok.dev, an Ansible role or a build task.

  • In Java, depend on dev.klok.framework:klok-common from the dependency catalog (klokLibs.klokCommon), or on the Java broker client, which brings it. Use KlokNamingConventions for topic names and companions, KlokMessageProperties and KlokCloudEventAttributes for what goes on a message, and KlokTopicProvisioning to report a missing topic or grant in the platform's words.
  • In any other language, do not port the Java source. Take the wire contract of the klok-common release in the catalog, the wire-contract zip classifier of the Maven artifact (dev.klok.framework:klok-common:<version>:wire-contract@zip) or the same files inside the jar, vendor it, and run every case of its fixture files in your own tests. The contract states the property names and who sets them, the topic grammar and companions, request/reply, the metadata a consumer and a producer announce, the connection rules and the service logging. The TypeScript and Python broker clients and klok.dev are the existing copies; their paths are in the wire contract page.
  • Take the tenant from the topic, never from the message. parseTopicName (or topics in the contract) gives the tenant, environment, domain, datamodel and purpose of any topic name.
  • When the contract changes, copy the new files and run the cases again. A new property or case is an ordinary release; a renamed one raises contractVersion.

For the maintainer who changes and releases it

  1. Work in a worktree and change the data first. A new name or rule goes into src/main/resources/dev/klok/wire-contract/ (the contract JSON and a fixture case) before the Java constant; KlokWireContractParityTest fails until both agree. A helper belongs here only when at least two modules use it (Design decisions).
  2. Build and test with ./gradlew build on Java 21. The build resolves from Maven Central only and needs no token.
  3. Set the version in gradle.properties (majorVersion, minorVersion, patchVersion); the pipeline appends the build timestamp.
  4. Open a merge request with a Conventional Commits title. Its type decides the pipeline on main: feat, fix and the others release a new version; docs, for a change to klok-docs/ or the README only, builds and publishes the documentation and releases nothing.
  5. After the merge, the main pipeline releases the jar and the wire contract zip to the GitLab package registry and to Maven Central (release_and_publish_job, which may wait up to an hour for Maven Central), then update_klok_catalog writes klokCommon into the dependency catalog and runs klok catalog release-dependents, which starts the pipeline of each framework library that follows the catalog and was built against an older klok-common (Releasing the dependents). Wait for the catalog commit, not for the merge:
glab api --hostname git.klok.dev "projects/klok%2Fframework%2Fklok-gradle-dependency-catalog/repository/commits?ref_name=main&per_page=10" | jq -r '.[].title'
  1. The dependents follow by themselves, in order: klok-common, then the broker client and the Gradle plugin, then the Quarkus extension. Each takes klok-common from the catalog, so the command starts its pipeline. The wire contract copies come along: the job that builds a client or klok.dev runs klok vendor sync --latest, and a copy's tests then run the new cases (Wire contract).