confluent-kafka-dotnet
Show / Hide Table of Contents

Class CachedSchemaRegistryClient

A caching Schema Registry client.

The following method calls cache results:

  • GetSchemaIdAsync(string, Schema, bool)
  • GetSchemaIdAsync(string, string, bool)
  • GetSchemaAsync(int, string)
  • GetSchemaBySubjectAndIdAsync(string, int, string)
  • RegisterSchemaAsync(string, Schema, bool)
  • RegisterSchemaAsync(string, string, bool)
  • GetRegisteredSchemaAsync(string, int, bool)
  • LookupSchemaAsync(string, Schema, bool, bool)

The following method calls do NOT cache results:

  • GetLatestSchemaAsync(string)
  • GetAllSubjectsAsync()
  • GetSubjectVersionsAsync(string)
  • IsCompatibleAsync(string, Schema)
  • IsCompatibleAsync(string, string)
  • GetCompatibilityAsync(string)
  • UpdateCompatibilityAsync(Compatibility, string)
Inheritance
object
CachedSchemaRegistryClient
Implements
ISchemaRegistryClient
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.SchemaRegistry
Assembly: Confluent.SchemaRegistry.dll
Syntax
public class CachedSchemaRegistryClient : ISchemaRegistryClient, IDisposable

Constructors

CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>>)

Initialize a new instance of the SchemaRegistryClient class.

Declaration
public CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>> config)
Parameters
TypeNameDescription
IEnumerable<KeyValuePair<string, string>>config

Configuration properties.

CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>>, IAuthenticationHeaderValueProvider, IWebProxy)

Initialize a new instance of the SchemaRegistryClient class with a custom IAuthenticationHeaderValueProvider

Declaration
public CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>> config, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider, IWebProxy proxy = null)
Parameters
TypeNameDescription
IEnumerable<KeyValuePair<string, string>>config

Configuration properties.

IAuthenticationHeaderValueProviderauthenticationHeaderValueProvider

The authentication header value provider

IWebProxyproxy

The proxy server to use for connections

CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>>, IWebProxy)

Initialize a new instance of the SchemaRegistryClient class.

Declaration
public CachedSchemaRegistryClient(IEnumerable<KeyValuePair<string, string>> config, IWebProxy proxy)
Parameters
TypeNameDescription
IEnumerable<KeyValuePair<string, string>>config

Configuration properties.

IWebProxyproxy

The proxy server to use for connections

Fields

DefaultEnableSslCertificateVerification

The default SSL server certificate verification for Schema Registry REST API calls.

Declaration
public const bool DefaultEnableSslCertificateVerification = true
Field Value
TypeDescription
bool

DefaultKeySubjectNameStrategy

The default key subject name strategy.

Declaration
public const SubjectNameStrategy DefaultKeySubjectNameStrategy = Topic
Field Value
TypeDescription
SubjectNameStrategy

DefaultLatestCacheTtlSecs

The default TTL for caches holding latest schemas.

Declaration
public const int DefaultLatestCacheTtlSecs = -1
Field Value
TypeDescription
int

DefaultMaxCachedSchemas

The default maximum capacity of the local schema cache.

Declaration
public const int DefaultMaxCachedSchemas = 1000
Field Value
TypeDescription
int

DefaultMaxConnectionsPerServer

The default maximum number of connections per server.

Declaration
public const int DefaultMaxConnectionsPerServer = 20
Field Value
TypeDescription
int

DefaultMaxRetries

The default maximum number of retries.

Declaration
public const int DefaultMaxRetries = 3
Field Value
TypeDescription
int

DefaultRetriesMaxWaitMs

The default time to wait for any retry.

Declaration
public const int DefaultRetriesMaxWaitMs = 20000
Field Value
TypeDescription
int

DefaultRetriesWaitMs

The default time to wait for the first retry.

Declaration
public const int DefaultRetriesWaitMs = 1000
Field Value
TypeDescription
int

DefaultTimeout

The default timeout value for Schema Registry REST API calls.

Declaration
public const int DefaultTimeout = 30000
Field Value
TypeDescription
int

DefaultValueSubjectNameStrategy

The default value subject name strategy.

Declaration
public const SubjectNameStrategy DefaultValueSubjectNameStrategy = Topic
Field Value
TypeDescription
SubjectNameStrategy

Properties

AuthHeaderProvider

The authentication header provider.

Declaration
public IAuthenticationHeaderValueProvider AuthHeaderProvider { get; }
Property Value
TypeDescription
IAuthenticationHeaderValueProvider

Config

The client config.

Declaration
public IEnumerable<KeyValuePair<string, string>> Config { get; }
Property Value
TypeDescription
IEnumerable<KeyValuePair<string, string>>

MaxCachedSchemas

The maximum capacity of the local schema cache.

Declaration
public int MaxCachedSchemas { get; }
Property Value
TypeDescription
int

Proxy

The web proxy.

Declaration
public IWebProxy Proxy { get; }
Property Value
TypeDescription
IWebProxy

Methods

ClearCaches()

Clears all caches.

Declaration
public void ClearCaches()

ClearLatestCaches()

Clears caches of latest versions.

Declaration
public void ClearLatestCaches()

ConstructKeySubjectName(string, string)

DEPRECATED. SubjectNameStrategy should now be specified via serializer configuration. Returns the schema registry key subject name given a topic name.

Declaration
[Obsolete("SubjectNameStrategy should now be specified via serializer configuration. This method will be removed in a future release.")]
public string ConstructKeySubjectName(string topic, string recordType = null)
Parameters
TypeNameDescription
stringtopic

The topic name.

stringrecordType

The fully qualified record type. May be null if not required by the configured subject naming strategy.

Returns
TypeDescription
string

The key subject name given a topic name.

ConstructValueSubjectName(string, string)

DEPRECATED. SubjectNameStrategy should now be specified via serializer configuration. Returns the schema registry value subject name given a topic name.

Declaration
[Obsolete("SubjectNameStrategy should now be specified via serializer configuration. This method will be removed in a future release.")]
public string ConstructValueSubjectName(string topic, string recordType = null)
Parameters
TypeNameDescription
stringtopic

The topic name.

stringrecordType

The fully qualified record type. May be null if not required by the configured subject naming strategy.

Returns
TypeDescription
string

The value subject name given a topic name.

Dispose()

Releases unmanaged resources owned by this CachedSchemaRegistryClient instance.

Declaration
public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by this object and optionally disposes the managed resources.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
booldisposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetAllSubjectsAsync()

Gets a list of all subjects with registered schemas.

Declaration
public Task<List<string>> GetAllSubjectsAsync()
Returns
TypeDescription
Task<List<string>>

A list of all subjects with registered schemas.

GetCompatibilityAsync(string)

If the subject is specified returns compatibility type for the specified subject. Otherwise returns global compatibility type.

Declaration
public Task<Compatibility> GetCompatibilityAsync(string subject = null)
Parameters
TypeNameDescription
stringsubject

The subject to get the compatibility for.

Returns
TypeDescription
Task<Compatibility>

Compatibility type.

GetLatestSchemaAsync(string)

Get the latest schema registered against the specified subject.

Declaration
public Task<RegisteredSchema> GetLatestSchemaAsync(string subject)
Parameters
TypeNameDescription
stringsubject

The subject to get the latest associated schema for.

Returns
TypeDescription
Task<RegisteredSchema>

The latest schema registered against subject.

GetLatestWithMetadataAsync(string, IDictionary<string, string>, bool)

Get the latest schema with the given metadata registered against the specified subject.

Declaration
public Task<RegisteredSchema> GetLatestWithMetadataAsync(string subject, IDictionary<string, string> metadata, bool ignoreDeletedSchemas)
Parameters
TypeNameDescription
stringsubject

The subject to get the latest associated schema for.

IDictionary<string, string>metadata

The metadata to search for.

boolignoreDeletedSchemas

Whether to ignore deleted schemas.

Returns
TypeDescription
Task<RegisteredSchema>

The latest schema with the given metadata registered against subject.

GetRegisteredSchemaAsync(string, int, bool)

Gets a schema given a subject and version number.

Declaration
public Task<RegisteredSchema> GetRegisteredSchemaAsync(string subject, int version, bool ignoreDeletedSchemas = true)
Parameters
TypeNameDescription
stringsubject

The subject to get the schema for.

intversion

The version number of schema to get.

boolignoreDeletedSchemas

Whether or not to ignore deleted schemas.

Returns
TypeDescription
Task<RegisteredSchema>

The schema identified by the specified subject and version.

GetSchemaAsync(int, string)

Gets the schema uniquely identified by id.

Declaration
public Task<Schema> GetSchemaAsync(int id, string format = null)
Parameters
TypeNameDescription
intid

The unique id of schema to get.

stringformat

The format of the schema to get. Currently, the only supported value is "serialized", and this is only valid for protobuf schemas. If 'serialized', the SchemaString property of the returned value will be a base64 encoded protobuf file descriptor. If null, SchemaString will be human readable text.

Returns
TypeDescription
Task<Schema>

The schema identified by id.

GetSchemaAsync(string, int)

DEPRECATED. Superseded by GetRegisteredSchemaAsync(string subject, int version) Gets a schema given a subject and version number.

Declaration
[Obsolete("Superseded by GetRegisteredSchemaAsync(string subject, int version). This method will be removed in a future release.")]
public Task<string> GetSchemaAsync(string subject, int version)
Parameters
TypeNameDescription
stringsubject

The subject to get the schema for.

intversion

The version number of schema to get.

Returns
TypeDescription
Task<string>

The schema identified by the specified subject and version.

GetSchemaByGuidAsync(string, string)

Gets the schema uniquely identified by guid.

Declaration
public Task<Schema> GetSchemaByGuidAsync(string guid, string format = null)
Parameters
TypeNameDescription
stringguid

The globally unique id of schema to get.

stringformat

The format of the schema to get. Currently, the only supported value is "serialized", and this is only valid for protobuf schemas. If 'serialized', the SchemaString property of the returned value will be a base64 encoded protobuf file descriptor. If null, SchemaString will be human readable text.

Returns
TypeDescription
Task<Schema>

The schema identified by guid.

GetSchemaBySubjectAndIdAsync(string, int, string)

Gets the schema uniquely identified by subject and id.

Declaration
public Task<Schema> GetSchemaBySubjectAndIdAsync(string subject, int id, string format = null)
Parameters
TypeNameDescription
stringsubject

The subject.

intid

The unique id of schema to get.

stringformat

The format of the schema to get. Currently, the only supported value is "serialized", and this is only valid for protobuf schemas. If 'serialized', the SchemaString property of the returned value will be a base64 encoded protobuf file descriptor. If null, SchemaString will be human readable text.

Returns
TypeDescription
Task<Schema>

The schema identified by id.

GetSchemaIdAsync(string, Schema, bool)

Get the unique id of the specified schema registered against the specified subject.

Declaration
public Task<int> GetSchemaIdAsync(string subject, Schema schema, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject the schema is registered against.

Schemaschema

The schema to get the id for.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<int>

The unique id identifying the schema.

Exceptions
TypeCondition
SchemaRegistryException

Thrown if the schema is not registered against the subject.

GetSchemaIdAsync(string, string, bool)

Get the unique id of the specified avro schema registered against the specified subject.

Declaration
public Task<int> GetSchemaIdAsync(string subject, string avroSchema, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject the schema is registered against.

stringavroSchema

The schema to get the id for.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<int>

The unique id identifying the schema.

Exceptions
TypeCondition
SchemaRegistryException

Thrown if the schema is not registered against the subject.

GetSubjectVersionsAsync(string)

Gets a list of versions registered under the specified subject.

Declaration
public Task<List<int>> GetSubjectVersionsAsync(string subject)
Parameters
TypeNameDescription
stringsubject

The subject to get versions registered under.

Returns
TypeDescription
Task<List<int>>

A list of versions registered under the specified subject.

IsCompatibleAsync(string, Schema)

Check if a schema is compatible with latest version registered against a specified subject.

Declaration
public Task<bool> IsCompatibleAsync(string subject, Schema schema)
Parameters
TypeNameDescription
stringsubject

The subject to check.

Schemaschema

The schema to check.

Returns
TypeDescription
Task<bool>

true if schema is compatible with the latest version registered against a specified subject, false otherwise.

IsCompatibleAsync(string, string)

Check if an avro schema is compatible with latest version registered against a specified subject.

Declaration
public Task<bool> IsCompatibleAsync(string subject, string avroSchema)
Parameters
TypeNameDescription
stringsubject

The subject to check.

stringavroSchema

The schema to check.

Returns
TypeDescription
Task<bool>

true if avroSchema is compatible with the latest version registered against a specified subject, false otherwise.

LookupSchemaAsync(string, Schema, bool, bool)

Get the registered schema details (including version and id) given a subject name and schema, or throw an exception if the schema is not registered against the subject.

Declaration
public Task<RegisteredSchema> LookupSchemaAsync(string subject, Schema schema, bool ignoreDeletedSchemas, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject name the schema is registered against.

Schemaschema

The schema to lookup.

boolignoreDeletedSchemas

Whether or not to ignore deleted schemas.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<RegisteredSchema>

The schema identified by the specified subject and schema.

RegisterSchemaAsync(string, Schema, bool)

Register a schema or get the schema id if it's already registered.

Declaration
public Task<int> RegisterSchemaAsync(string subject, Schema schema, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject to register the schema against.

Schemaschema

The schema to register.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<int>

A unique id identifying the schema.

RegisterSchemaAsync(string, string, bool)

Register an Avro schema or get the schema id if it's already registered.

Declaration
public Task<int> RegisterSchemaAsync(string subject, string avroSchema, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject to register the schema against.

stringavroSchema

The schema to register.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<int>

A unique id identifying the schema.

RegisterSchemaWithResponseAsync(string, Schema, bool)

Register a schema or get the schema id if it's already registered.

Declaration
public Task<RegisteredSchema> RegisterSchemaWithResponseAsync(string subject, Schema schema, bool normalize = false)
Parameters
TypeNameDescription
stringsubject

The subject to register the schema against.

Schemaschema

The schema to register.

boolnormalize

Whether to normalize schemas.

Returns
TypeDescription
Task<RegisteredSchema>

The schema.

UpdateCompatibilityAsync(Compatibility, string)

If the subject is specified sets compatibility type for the specified subject. Otherwise sets global compatibility type.

Declaration
public Task<Compatibility> UpdateCompatibilityAsync(Compatibility compatibility, string subject = null)
Parameters
TypeNameDescription
Compatibilitycompatibility

Compatibility type.

stringsubject

The subject to set the compatibility for.

Returns
TypeDescription
Task<Compatibility>

New compatibility type.

Implements

ISchemaRegistryClient
IDisposable
In this article