Skip to main content

Actions

The ballerinax/confluent.cregistry package exposes the following clients:

ClientPurpose
ClientRegisters and retrieves schemas from Confluent Schema Registry.

Client

Registers and retrieves schemas from Confluent Schema Registry.

Configuration

FieldTypeDefaultDescription
baseUrlstringRequiredThe base URL of the Schema Registry endpoint (e.g., https://psrc-xxxxx.us-east-2.aws.confluent.cloud).
identityMapCapacityint1000Capacity of the schema ID map for a particular subject.
originalsmap<anydata>()Connection configurations for authentication and SSL (e.g., basic auth credentials, truststore settings).
headersmap<string>()Custom HTTP headers to include in requests to the Schema Registry.

Initializing the client

import ballerinax/confluent.cregistry;

configurable string baseUrl = ?;
configurable string apiKey = ?;
configurable string apiSecret = ?;

cregistry:Client schemaRegistryClient = check new (
baseUrl = baseUrl,
originals = {
"basic.auth.credentials.source": "USER_INFO",
"basic.auth.user.info": string `${apiKey}:${apiSecret}`
}
);

Operations

Schema operations

register

Registers a schema under the specified subject in the Schema Registry. Returns the unique schema ID assigned by the registry.

Parameters:

NameTypeRequiredDescription
subjectstringYesThe subject name under which to register the schema (e.g., "my-topic-value").
schemastringYesThe schema definition as a JSON string (e.g., an Avro schema).

Returns: int|error

Sample code:

string schema = string `
{
"namespace": "example.avro",
"type": "record",
"name": "Student",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_color", "type": ["string", "null"]}
]
}`;

int registerId = check schemaRegistryClient->register("student-topic-value", schema);

Sample response:

1
getSchemaById

Retrieves a schema from the Schema Registry by its unique schema ID. Returns the schema definition as a string.

Parameters:

NameTypeRequiredDescription
idintYesThe unique ID of the schema to retrieve.

Returns: string|error

Sample code:

string schema = check schemaRegistryClient->getSchemaById(1);

Sample response:

{"type":"record","name":"Student","namespace":"example.avro","fields":[{"name":"name","type":"string"},{"name":"favorite_color","type":["string","null"]}]}