A payload that is too large for a broker message is kept in the platform's object storage, RustFS with the S3 API, and
the message carries a reference to it: the claim check pattern. The Quarkus extension has done this for routes since 2.0
(KlokClaimCheckStore, the ClaimCheck capability). The Java and the TypeScript clients have the same store, so that a
process outside the extension (a Gradle task, klok-cli, a Node backend) stores and loads with the same keys and
references as a route. This page is for the developer of such a process.
It was added for the documentation senders, ./gradlew publishKlokDocs (klok-gradle-plugin) and klok docs send
(klok-cli), so that they can store a documentation payload above 3 MiB and publish only its reference, which
KlokDocumentationEgress reads back
(klok-gradle-plugin#13).
What it stores, and where
- One bucket per tenant,
klok-<tenant>-claimcheck, unless KLOK_BLOBSTORE_BUCKET names another. The store never
creates a bucket: claim check buckets are provisioned with their lifecycle rule in klok-environment-setup
(rustfs.yml), and one that is missing is reported as NO_SUCH_BUCKET.
- Content addressed keys,
<scope>/<tenant>/<domain>/<sha256>, with scope, tenant and domain in lower case: the
extension's S3ClaimCheckStore.keyFor. The same bytes give the same key and are uploaded once. tmp/ expires with the
bucket's rule (seven days on the platform); perm/ is kept until it is deleted.
- Metadata on every object:
sha256, filename, klok-tenant, klok-domain and, when given, klok-route-id, as
the extension writes them. A file name that is not ASCII is percent encoded in the metadata and kept as it is in the
reference.
- The reference is the extension's
KlokClaimCheckRefV1 and the fields of the datamodel KlokClaimCheckRef_v1, with
the text form klokcc://<bucket>/<key>?sha256=<hex>&size=<bytes>&ct=<content type>&name=<file name> that travels in the
property klok-claimcheck-ref or a datamodel's uri. Both clients write and read it byte for byte as Java does: the
shared cases in src/test/resources/claim-check-cases.json were written by the extension's own class.
Configuration
The extension's klok.blobstore.* keys, as environment variables:
| Variable |
Default |
Meaning |
KLOK_BLOBSTORE_ENDPOINT |
required |
the S3 endpoint; RustFS on the platform is http://10.174.93.19:9000 |
KLOK_BLOBSTORE_ACCESS_KEY, KLOK_BLOBSTORE_SECRET_KEY |
required |
the key; on the platform one RustFS user per consumer, whose access key is its name |
KLOK_BLOBSTORE_BUCKET |
klok-<tenant>-claimcheck |
the bucket |
KLOK_BLOBSTORE_REGION |
us-east-1 |
the signing region |
KLOK_BLOBSTORE_VERIFY_SHA256 |
true |
whether a load checks the bytes against the reference's sha256 |
KLOK_TENANT, KLOK_DOMAIN |
local, common |
the tenant and domain of the keys this process stores, as the extension's defaults |
A store without endpoint or key does not start: it fails with NOT_CONFIGURED and names the missing variables, so a
caller can say "not configured" rather than "could not deliver". Requests are path style over HTTP/1.1 and signed with
Signature Version 4; the clients carry no AWS SDK.
Java
KlokClaimCheckStore store = new KlokClaimCheckStore(KlokClaimCheckConfig.fromEnv());
KlokClaimCheckRef ref = store.store(bytes, "application/json", "payload.json");
// or with scope, tenant, domain and the writing route: store(bytes, contentType, fileName, "tmp", "klok", "common", routeId)
ref.toUri(); // klokcc://klok-klok-claimcheck/tmp/klok/common/<sha256>?sha256=...&size=...&ct=application%2Fjson&name=payload.json
byte[] back = store.load(KlokClaimCheckRef.fromUri(uri));
store.head(ref); // Optional<KlokStoredObject>: size, content type, entity tag, last change, metadata
store.delete(ref);
KlokClaimCheckConfig.fromEnv().withTenant("klok", "common") scopes the keys to a tenant that the environment does not
name, with that tenant's bucket unless KLOK_BLOBSTORE_BUCKET is set. KlokClaimCheckRef.of(bytes, bucket, scope, tenant, domain, contentType, fileName) computes the reference without storing anything. Failures are a checked
KlokClaimCheckException with a code().
TypeScript
import { KlokClaimCheckRef, KlokClaimCheckStore, claimCheckConfigFromEnv } from '@klok-integration/brokerclient';
const store = new KlokClaimCheckStore(claimCheckConfigFromEnv(process.env, { tenant: 'klok', domain: 'common' }));
const ref = await store.store(bytes, { contentType: 'application/json', fileName: 'payload.json', routeId: 'ACM010P1_Export' });
ref.toUri();
const back = await store.load(KlokClaimCheckRef.fromUri(uri));
claimCheckRef(bytes, { bucket, tenant, domain, contentType, fileName }) computes the reference without storing, which
is what a dry run reports; missingClaimCheckSettings(config) names what the environment lacks. Failures are a
KlokClaimCheckException with a code.
How a store call behaves
- Store looks the key up first (HEAD). An object that is there is not uploaded again. A key that may write but not
read gets a 403 on the lookup and uploads at once, so a consumer can be given a write-only key.
- Load reads the object (GET) and, unless
KLOK_BLOBSTORE_VERIFY_SHA256 is false, checks it against the reference's
sha256.
- Errors say what to do, by
code: NOT_CONFIGURED, NOT_FOUND (the object is gone; tmp/ expires),
NO_SUCH_BUCKET, ACCESS_DENIED (names the key and the bucket), CORRUPT (the bytes are not the reference's),
REFUSED (another answer of the store) and UNAVAILABLE (no answer, or a 5xx). Only UNAVAILABLE is retryable.
Not there yet
- A message whose payload travels behind
klok-claimcheck-ref: resolving the property before decoding, and storing a
payload above a threshold on publish, as the extension's ClaimCheck capability does for routes. Both clients have the
store; the message level is the rest of #27
for TypeScript, and is not in the Java client either.
- The Quarkus extension keeps its own store on the AWS SDK. Moving it onto this one, so the platform has one
implementation, is
klok-quarkus-extension#59.
- Named objects (
storeAt in the extension), bucket creation and lifecycle rules are not in the clients' store, by
design: buckets and their rules are provisioned.
Testing
The unit tests run the shared cases and the Signature Version 4 examples of the S3 documentation (the same file in both
clients), and drive the store against a stand-in S3 that records every call. The tests against a real store run against
RustFS in the version klok-ai runs, started as a CI service in typescript-package-test and java-integration-test
(tag claimcheck); see Testing for running them on a laptop.