Class ConfluentSchemaRegistryClient
Confluent Schema Registry client implementation wrapping the Confluent SDK.
public sealed class ConfluentSchemaRegistryClient : ISchemaRegistryClient, IDisposable
- Inheritance
-
ConfluentSchemaRegistryClient
- Implements
- Inherited Members
- Extension Methods
Remarks
This class wraps the Confluent.SchemaRegistry SDK to provide a consistent interface for schema registry operations. It should be registered as a singleton.
Constructors
ConfluentSchemaRegistryClient(ConfluentSchemaRegistryOptions, ILogger<ConfluentSchemaRegistryClient>)
Initializes a new instance of the ConfluentSchemaRegistryClient class.
public ConfluentSchemaRegistryClient(ConfluentSchemaRegistryOptions options, ILogger<ConfluentSchemaRegistryClient> logger)
Parameters
optionsConfluentSchemaRegistryOptionsThe configuration options.
loggerILogger<ConfluentSchemaRegistryClient>The logger instance.
Methods
Dispose()
Disposes the client and releases resources.
public void Dispose()
GetSchemaByIdAsync(int, CancellationToken)
Gets the schema definition for a given schema ID.
public Task<string> GetSchemaByIdAsync(int schemaId, CancellationToken cancellationToken)
Parameters
schemaIdintThe schema ID to retrieve.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Exceptions
- SchemaRegistryException
Thrown when the schema ID is not found or the registry is unavailable.
GetSchemaIdAsync(string, string, CancellationToken)
Gets the schema ID for a given subject and schema definition.
public Task<int> GetSchemaIdAsync(string subject, string schema, CancellationToken cancellationToken)
Parameters
subjectstringThe schema subject (typically topic-key or topic-value).
schemastringThe schema definition (JSON, Avro, Protobuf).
cancellationTokenCancellationTokenThe cancellation token.
Returns
Exceptions
- SchemaRegistryException
Thrown when the schema cannot be found or the registry is unavailable.
IsCompatibleAsync(string, string, CancellationToken)
Checks if a schema is compatible with the latest version under the specified subject.
public Task<bool> IsCompatibleAsync(string subject, string schema, CancellationToken cancellationToken)
Parameters
subjectstringThe schema subject to check compatibility against.
schemastringThe schema definition to validate.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Exceptions
- SchemaRegistryException
Thrown when the compatibility check fails or the registry is unavailable.
RegisterSchemaAsync(string, string, CancellationToken)
Registers a new schema under the specified subject.
public Task<int> RegisterSchemaAsync(string subject, string schema, CancellationToken cancellationToken)
Parameters
subjectstringThe schema subject (typically topic-key or topic-value).
schemastringThe schema definition to register.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Exceptions
- SchemaRegistryException
Thrown when the schema registration fails or the registry is unavailable.