Class KrabkaSchemaRegistryClient
Every operation returns a CompletableFuture and no method blocks the
calling thread; requests run on the HttpClient's executor. Transport errors,
HTTP 429, and 5xx responses are retried up to the configured retry count. Failed
futures complete with SchemaRegistryException (usually wrapped in a
CompletionException).
Applications rarely call this client directly for serialization; they hand it to
a SchemaCache, which layers caching and prewarming on top. Direct use suits
tooling: registering schemas from a pipeline, checking compatibility levels, or
cleaning up subjects.
Example
var client = new KrabkaSchemaRegistryClient(URI.create("http://localhost:8081"));
int id = client.register("orders-value", SchemaKind.AVRO, orderSchema, null).join();
var latest = client.latest("orders-value").join();
List<String> subjects = client.subjects().join();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA schema fetched by ID, with unresolved references.static final recordOne registered version of a subject.static final recordA schema fetched by ID with every transitive reference resolved to its text.static final recordA reference from one schema to a version of another subject. -
Constructor Summary
ConstructorsConstructorDescriptionKrabkaSchemaRegistryClient(URI baseUri) Creates a client with a default HTTP client, default mapper, and two retries.KrabkaSchemaRegistryClient(URI baseUri, String username, String password) Creates a client that sends HTTP basic authentication with every request.KrabkaSchemaRegistryClient(URI baseUri, HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a client with caller-supplied HTTP client and mapper and two retries.KrabkaSchemaRegistryClient(URI baseUri, HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, int maxRetries) Creates a client with an explicit retry budget. -
Method Summary
Modifier and TypeMethodDescriptionReads the registry's global compatibility level.compatibility(String subject) Reads a subject's compatibility level.deleteSubject(String subject, boolean permanent) Deletes a subject and all of its versions.deleteVersion(String subject, int version, boolean permanent) Deletes one version of a subject.Fetches the latest registered version of a subject.Fetches the schema ID of a subject's latest version.lookup(String subject, SchemaKind kind, String schema, String messageType) Looks up the ID of an already registered schema without references.lookup(String subject, SchemaKind kind, String schema, String messageType, List<KrabkaSchemaRegistryClient.SchemaReference> references) Looks up the ID of an already registered schema with schema references.register(String subject, SchemaKind kind, String schema, String messageType) Registers a schema under a subject without references.register(String subject, SchemaKind kind, String schema, String messageType, List<KrabkaSchemaRegistryClient.SchemaReference> references) Registers a schema under a subject with schema references.resolvedSchemaById(int schemaId) Fetches a schema by ID and recursively resolves its references.schemaById(int schemaId) Fetches a schema by its global ID.setCompatibility(String level) Sets the registry's global compatibility level.setCompatibility(String subject, String level) Sets a subject's compatibility level.subjects()Lists all subject names.Fetches one specific version of a subject.Lists a subject's version numbers.
-
Constructor Details
-
KrabkaSchemaRegistryClient
Creates a client with a default HTTP client, default mapper, and two retries.- Parameters:
baseUri- the registry base URI, for examplehttp://localhost:8081
-
KrabkaSchemaRegistryClient
public KrabkaSchemaRegistryClient(URI baseUri, HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a client with caller-supplied HTTP client and mapper and two retries.- Parameters:
baseUri- the registry base URIhttpClient- the HTTP client that executes requestsobjectMapper- the mapper for request and response JSON
-
KrabkaSchemaRegistryClient
public KrabkaSchemaRegistryClient(URI baseUri, HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, int maxRetries) Creates a client with an explicit retry budget.- Parameters:
baseUri- the registry base URIhttpClient- the HTTP client that executes requestsobjectMapper- the mapper for request and response JSONmaxRetries- how many times a failed request is retried; zero disables retries- Throws:
IllegalArgumentException- ifmaxRetriesis negative
-
KrabkaSchemaRegistryClient
-
-
Method Details
-
register
public CompletableFuture<Integer> register(String subject, SchemaKind kind, String schema, String messageType) Registers a schema under a subject without references.Registration is idempotent: registering a schema the subject already has returns the existing ID.
- Parameters:
subject- the registry subject namekind- the schema formatschema- the schema textmessageType- the Protobuf message full name, or null for other formats- Returns:
- a future with the registered schema's ID
-
register
public CompletableFuture<Integer> register(String subject, SchemaKind kind, String schema, String messageType, List<KrabkaSchemaRegistryClient.SchemaReference> references) Registers a schema under a subject with schema references.- Parameters:
subject- the registry subject namekind- the schema formatschema- the schema textmessageType- the Protobuf message full name, or null for other formatsreferences- the schemas this schema refers to- Returns:
- a future with the registered schema's ID
-
lookup
public CompletableFuture<Integer> lookup(String subject, SchemaKind kind, String schema, String messageType) Looks up the ID of an already registered schema without references.- Parameters:
subject- the registry subject namekind- the schema formatschema- the schema text to look upmessageType- the Protobuf message full name, or null for other formats- Returns:
- a future with the schema's ID; fails with HTTP 404 when unregistered
-
lookup
public CompletableFuture<Integer> lookup(String subject, SchemaKind kind, String schema, String messageType, List<KrabkaSchemaRegistryClient.SchemaReference> references) Looks up the ID of an already registered schema with schema references.- Parameters:
subject- the registry subject namekind- the schema formatschema- the schema text to look upmessageType- the Protobuf message full name, or null for other formatsreferences- the schemas this schema refers to- Returns:
- a future with the schema's ID; fails with HTTP 404 when unregistered
-
latest
Fetches the latest registered version of a subject.- Parameters:
subject- the registry subject name- Returns:
- a future with the latest version's metadata and schema text
-
latestId
Fetches the schema ID of a subject's latest version.- Parameters:
subject- the registry subject name- Returns:
- a future with the latest version's schema ID
-
schemaById
Fetches a schema by its global ID.- Parameters:
schemaId- the registry schema ID- Returns:
- a future with the schema text and reference list; references are not resolved to their own schema texts
-
resolvedSchemaById
public CompletableFuture<KrabkaSchemaRegistryClient.ResolvedSchema> resolvedSchemaById(int schemaId) Fetches a schema by ID and recursively resolves its references.Each referenced subject version is fetched, and its own references are resolved transitively. Reference cycles are tolerated: a subject version already being resolved on the current path is skipped.
- Parameters:
schemaId- the registry schema ID- Returns:
- a future with the schema text and every transitive reference's text
-
subjects
Lists all subject names.- Returns:
- a future with every subject known to the registry
-
versions
Lists a subject's version numbers.- Parameters:
subject- the registry subject name- Returns:
- a future with the subject's version numbers in registry order
-
version
public CompletableFuture<KrabkaSchemaRegistryClient.RegisteredSchema> version(String subject, int version) Fetches one specific version of a subject.- Parameters:
subject- the registry subject nameversion- the version number to fetch- Returns:
- a future with the version's metadata and schema text
-
compatibility
Reads a subject's compatibility level.- Parameters:
subject- the registry subject name- Returns:
- a future with the compatibility level, for example
BACKWARD
-
compatibility
Reads the registry's global compatibility level.- Returns:
- a future with the global compatibility level
-
setCompatibility
Sets a subject's compatibility level.- Parameters:
subject- the registry subject namelevel- the level to set, for exampleBACKWARDorFULL- Returns:
- a future with the level the registry acknowledged
-
setCompatibility
Sets the registry's global compatibility level.- Parameters:
level- the level to set, for exampleBACKWARDorFULL- Returns:
- a future with the level the registry acknowledged
-
deleteSubject
Deletes a subject and all of its versions.- Parameters:
subject- the registry subject namepermanent- whether to hard-delete instead of soft-delete- Returns:
- a future with the deleted version numbers
-
deleteVersion
Deletes one version of a subject.- Parameters:
subject- the registry subject nameversion- the version number to deletepermanent- whether to hard-delete instead of soft-delete- Returns:
- a future with the deleted version number
-