Broker topics of a project
The Klok broker never creates a topic by itself. A topic exists when it is listed in its tenant's Pulsar file in Git
(klok/environment/klok-environment-setup, pulsar_tenant_<tenant>.yml) and that file has been applied; its _DLQ
topic, and the _Response topic of a _Request topic, are created with it. From klok-quarkus-extension 3.14.0, a
service whose topic or grant is missing holds the routes that need it and runs the rest; an older extension version does
not start at all. Two tasks tell a project, before it is deployed, which topics it needs and whether they are there:
klokTopics lists every topic the service needs in one environment, what it does on each and why, and writes the list
to build/klok-topics/topics.json.
klokTopicCheck builds the same list and asks klok.dev whether each topic is in Git, on the broker and granted to the
service's broker client. It fails the build when one is not, with the fix for each problem.
./gradlew klokTopics
./gradlew klokTopics --environment test
./gradlew klokTopicCheck --environment prod
./gradlew klokTopicCheck --report
klokTopics
The task reads the project's sources with the route scan of the documentation tasks (Documentation
tasks, The topics a route consumes and publishes) and
src/main/resources/application.properties, and lists the full names the framework resolves at run time:
persistent://<tenant>[_<environment>]/<domain>/<simple name>, built with klok-common's KlokNamingConventions.
| Option |
Default |
Meaning |
--environment <env> |
prod |
the environment to list for; prod has no suffix, any other is appended to the tenant (acme_test) |
--client-id <id> |
klok.broker.auth.client-id (or client_id) in application.properties, else the project name |
the broker client of the deployed service, whose grants klokTopicCheck asks about |
Where tenant and domain come from. From the same keys the service reads: klok.tenant and klok.domain in
application.properties, a %prod. key winning over the plain one, because a deployed service runs Quarkus' prod
profile in every Klok environment. A value ${NAME:default} is resolved by the deployment, so the task takes its
default and says so. Without klok.tenant the task uses the build's tenant (klok { tenant }, the GitLab root group)
and warns; without any tenant it fails, naming the key to set. Without klok.domain it uses klok { domain } when the
build sets one, with a warning that the service would use common, else common like the framework.
What a route's overrides move. <RouteId>.topic.tenant-override and .topic.domain-override (with the framework's
fallback chain, or an override of getTenantOverride() / getDomainOverride() in the route) choose what a route reads,
never where its output goes (write narrow, consume wide): a service publishes only in its own tenant, in its own
domain and in its tenant's common. The listing follows klok-quarkus-extension 3.18.0
(klok/framework/klok-quarkus-extension#30, #76):
| Topic |
Namespace |
The topic an offramp, sink channel adapter, processing route (KlokProcessingRoute, the schema bridges, KlokAsyncTaskWorkerRoute) or offramp with result consumes |
the override |
| The result a processing route or an offramp with result publishes |
the service's own tenant and domain (klok.tenant, klok.domain) |
The _DLQ of a consumed topic in the service's own tenant, in its own domain or common |
beside the topic, its companion |
The _DLQ of a consumed topic in another domain or tenant |
the same name in the service's own tenant and domain, persistent://<own tenant>[_<env>]/<own domain>/<Model>[_<purpose>]_DLQ |
| Every topic of an onramp, a channel adapter source or a request/reply pair |
the override |
KlokCloudEventV1_events |
the service's own tenant and domain |
| The task framework's topics, log events and the ODL |
the service's tenant, domain common |
So a route that reads <tenant>/common/KlokFileReceivedV1_<purpose> with topic.domain-override=common publishes its
result in its own domain, for example <tenant>/hr/PersonnelEmploymentBatchV1, and keeps
<tenant>/common/KlokFileReceivedV1_<purpose>_DLQ. A mail service in klok/mail that reads
klok/mailbox/KlokMailOutboundV1 (topic.domain-override=mailbox) lists klok/mail/KlokMailSendResultV1_klokai and
klok/mail/KlokMailOutboundV1_DLQ. That _DLQ has no topic of its own in klok/mail to come with, so the service's
tenant file lists it under topics:; klok_topic_check names it until it is there. A service on an extension before
3.18.0 still publishes where its overrides said; the listing describes 3.18.0 and later.
What is listed.
| Topics |
Access |
When |
| The pattern's data, request and response topics |
publish or consume |
every route, by its pattern (Documentation tasks) |
<consumed topic>_DLQ |
publish |
every route that consumes a data or request topic with dlq.enabled on (on by default for offramps, channel adapter sinks, offramps with result, processing routes and task workers; off for KlokOfframpRouteSync) |
KlokCloudEventV1_events in the service's own tenant and domain |
publish |
a route that implements KlokEmitCloudEventOnFailure, or KlokEmitCloudEventOnSuccess without publishing a result of its own (an onramp's or a processing route's success event rides on its message) |
KlokLogEventV4[_<klok.logevents.topic-purpose>] or KlokLogEventV6[_<klok.logevents.topic-purpose>] in common |
publish |
the project has routes and klok.logevents.enabled is not false |
KlokTaskV1, KlokTaskStatusEventV1 and KlokTaskStatusEventV1_<taskType> in common, where the task materializer and klok-api-tasks run |
publish |
a task worker (taskType()), a route with task.initiate (each type of task.type, comma separated, else the route id), a route with task.complete=true (status events only), or project code that calls KlokTaskService or KlokTaskContext; the per type topic only while klok.task.status-topic-per-type is on |
KlokTaskCommandV1 in common, where klok-api-tasks publishes cancellations |
consume, subscription KlokTaskCancellationRegistry-<klok.instance> |
a task worker, which listens for CANCEL |
KlokOdlPersistV1, KlokOdlBulkPersistV1, KlokOdlDeleteV1 and the ReqRes_KlokOdl… pairs in common |
publish, and consume of the response |
the project's code calls the matching KlokOdl method (persist, bulkPersist, delete, persistSync, deleteSync, deleteByQuerySync, get, search, searchAll) |
Which log events datamodel is listed. From klok-quarkus-extension 3.17.0, BrokerLogEventPublisher publishes
KlokLogEventV6 instead of KlokLogEventV4 (see klok-common's Log fields and correlation page,
klok/framework/klok-quarkus-extension!62). klokTopics reads the extension version the project's version catalogs
resolve for dev.klok.framework:klok-quarkus-extension (klokQuarkusExtension in klok-libs.versions.toml, kept
current by the weekly fleet job) and lists:
KlokLogEventV6 from 3.17.0 or later.
KlokLogEventV4 for an older, known version.
KlokLogEventV6, with a warning, when no version catalog of the build names the extension at all (a project that does
not apply klok-gradle-plugin's version catalogs, or whose catalog has not been refreshed): an unversioned project is
not safely assumed to still be on the old extension.
A consumed data or request topic carries the route's subscription: <RouteId>.subscription.name through the framework's
fallback chain, or an override of subscriptionIntention() in the route, else the route id. A requester reads its
_Response topic with a non-durable subscription of its own (reply-subscriber-<client>-<uuid>), listed as
reply-subscriber-*. Topics the service does not use itself, such as the _DLQ of a topic it only publishes on, are
not listed: they are created with their topic.
Warnings, never silence. A purpose, subscription, override or task type the scan cannot know (computed in code, a
${...} without default, a masked value), an ODL call through another type, or KlokTaskInitiator, which publishes on
<Request>_<taskType> with a type chosen at run time: the topic is not in the list, and a warning names the route and
the reason. A run with warnings is not proof that the list is complete.
The task prints a table (ACCESS, TOPIC, SUBSCRIPTION, ROUTE, WHY), then the warnings, and writes
build/klok-topics/topics.json:
{
"schemaVersion" : 1,
"generator" : "klok-gradle-plugin/<version>",
"projectPath" : "acme/integration/domain/finance/acme-orders-integration",
"projectName" : "acme-orders-integration",
"clientId" : "acme-orders-integration",
"tenant" : "acme",
"domain" : "finance",
"environment" : "prod",
"topics" : [ {
"topic" : "persistent://acme/finance/OrderV1_received",
"access" : "consume",
"subscription" : "ACM001P1_OrderEnricher",
"subscriptionMode" : "durable",
"routeId" : "ACM001P1_OrderEnricher",
"purpose" : "received",
"pattern" : "KlokProcessingRoute",
"model" : "OrderV1",
"kind" : "data",
"source" : "route",
"reason" : "The route consumes OrderV1 (KlokProcessingRoute)",
"companions" : [ "persistent://acme/finance/OrderV1_received_DLQ" ]
} ],
"warnings" : [ "Route ACM001E2_RegionalCopy: the consumed topic is left empty because its purpose is unknown: ..." ]
}
| Field |
Meaning |
topic |
the full topic name |
access |
publish or consume |
subscription, subscriptionMode |
for consume only: the subscription and durable or non-durable |
routeId, pattern |
the route that needs the topic; absent for a topic the framework uses for the whole application |
purpose, model |
the purpose part of the name (absent for none) and the datamodel on the topic |
kind |
data, request, response, dlq, cloudevents, logevents, odl or task |
source |
route (the pattern's topics), companion (a dead letter topic) or framework (the framework's own topics) |
reason |
why the service needs the topic, one sentence |
companions |
the topics created with it (KlokNamingConventions.companionTopics) |
The file is the contract with klokTopicCheck, the deploy job and any tool or agent that reads it; a change of its form
raises schemaVersion.
klokTopicCheck
Lists the topics exactly like klokTopics (same options, same topics.json), then sends
POST <KLOK_DEV_URL>/api/integration-context/topic-check
Authorization: Bearer <KLOK_INTEGRATION_CONTEXT_TOKEN>
{ "projectPath": "...", "clientId": "...", "environment": "prod",
"topics": [ { "topic": "...", "access": "consume", "subscription": "...", "routeId": "...", "purpose": "..." } ] }
klok.dev compares the list with the tenant's Pulsar file in Git, with the broker and with the grants of
service-account-<clientId>, and answers per topic {topic, access, inGit, onBroker, granted, problems: [{code, message, ownerHint, requestUrl, gitEntry}]} with a top level ok. The task writes the answer to
build/klok-topics/topic-check.json, prints it, and fails the build when ok is false. The endpoint belongs to
klok.dev (klok/application/frontend-klok-dev); a klok.dev without it answers 404, which the task reports like any
other HTTP error.
| Setting |
Source |
Default |
| klok.dev URL |
KLOK_DEV_URL, else klokDocs.contextUrl |
https://klok.dev |
| token |
KLOK_INTEGRATION_CONTEXT_TOKEN, the same token publishKlokContext uses |
none |
| strict |
CI=true |
a developer's machine |
--report |
command line |
off |
When the check cannot run (no URL, no token, klok.dev unreachable, 401, 403, 5xx, an answer that is not a
check result): in CI the build fails with what to configure; on a developer's machine the task warns and skips, so a
local build works offline. --report prints whatever klok.dev answered and never fails.
Reading a failure
Each problem is one numbered block:
1. TOPIC_MISSING persistent://acme/finance/OrderV1_received (publish, route ACM001I1_OrderOnramp)
TOPIC_MISSING: the topic persistent://acme/finance/OrderV1_received does not exist, so service-account-... cannot publish on it.
...
Owner: a TenantAdmin of acme or a DomainAdmin of acme/finance
Request it: https://klok.dev/monitoring/broker/request?topic=persistent%3A%2F%2Facme%2Ffinance%2FOrderV1_received&access=create
By hand, in the tenant's Pulsar file (klok/environment/klok-environment-setup, ansible-master/playbooks/group_vars/all/pulsar_tenant_acme.yml):
topics:
- persistent://acme/finance/OrderV1_received
| Code |
Means |
Fix |
TOPIC_MISSING |
the topic is not in the tenant's Pulsar file |
request it with the link (an owner approves), or add the Git entry in a merge request |
TOPIC_ACCESS_DENIED |
the service's broker client may not publish or consume on it |
request the access with the link, or add the grant in a merge request; publish in another tenant's or domain's namespace is never granted (write narrow, consume wide) |
NOT_APPLIED |
the entry is in Git but not on the broker yet |
nothing to request; the owner applies the tenant file |
When klok.dev leaves a message, link or owner out, the task fills it in with the wire contract's text from klok-common
(KlokTopicProvisioning), so the message a developer reads here is the one the framework logs when a service fails to
start on the same problem.
Who uses the tasks, and how
An integration developer runs ./gradlew klokTopics after adding or changing a route, a purpose or an override,
reads the table, and fixes every warning so the list is complete (a purpose in application.properties or a constant
the route returns). Before the first deploy of a new topic, ./gradlew klokTopicCheck with
KLOK_INTEGRATION_CONTEXT_TOKEN exported shows what is missing, and each request link opens klok.dev's request page for
that topic.
The integration build template runs it in its job klok_topic_check: ./gradlew klokTopicCheck --environment "$KLOK_TOPIC_CHECK_ENVIRONMENT" (default prod) after the Vault login that exports KLOK_DEV_URL and
KLOK_INTEGRATION_CONTEXT_TOKEN, with CI=true as every GitLab job has it, next to the image build, and
update_manifest waits for it. Whether a failure stops the deployment is the CI variable KLOK_TOPIC_CHECK: with
enforce a failed check on main stops the deploy before a service starts against a topic it cannot use; with the
default report, and in every merge request and branch pipeline, the job is allowed to fail, so the problem shows as a
warning and blocks nothing (The topic check in the release
process).
A tenant or domain owner receives the requests the links create in klok.dev, approves them there, or merges the Git
entry; NOT_APPLIED means the tenant file waits to be applied.
An AI agent working in a Klok project:
- Runs
./gradlew klokTopics and reads build/klok-topics/topics.json, not the console, for the list.
- Treats every entry in
warnings as work: make the purpose, subscription or override something the scan can read, or say
in the merge request which topic it cannot list and why.
- Runs
./gradlew klokTopicCheck --report when a token is available, and reads build/klok-topics/topic-check.json.
- Never creates a topic or a grant on the broker. For each problem it hands the person the request link and the owner, or
opens the merge request with the Git entry in
klok/environment/klok-environment-setup when the task asks for it, and
lists both as manual steps.