confluent-kafka-dotnet
Show / Hide Table of Contents

Class AssociatedNameStrategy

Associated subject name strategy implementation that uses a schema registry client and configuration to determine subject names.

This strategy queries schema registry for the associated subject name for the topic. The topic is passed as the resource name to schema registry. If there is a configuration property named "subject.name.strategy.kafka.cluster.id", then its value will be passed as the resource namespace. Otherwise, if the producer or consumer supplied a cluster id resolver via SetClusterIdResolver(Func<Task<string>>), the id it resolves to is used, resolved when the association is looked up. Failing both, the value "-" will be passed as the resource namespace.

If more than one subject is returned from the query, an exception will be thrown. If no subjects are returned from the query, then the behavior will fall back to Topic strategy, unless the configuration property "subject.name.strategy.fallback.type" is set to "RECORD", "TOPIC_RECORD", or "NONE".

Inheritance
object
AssociatedNameStrategy
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 AssociatedNameStrategy

Constructors

AssociatedNameStrategy(ISchemaRegistryClient, IEnumerable<KeyValuePair<string, string>>)

Initializes a new instance of the AssociatedNameStrategy class.

Declaration
public AssociatedNameStrategy(ISchemaRegistryClient schemaRegistryClient, IEnumerable<KeyValuePair<string, string>> config)
Parameters
Type Name Description
ISchemaRegistryClient schemaRegistryClient

The schema registry client to use for lookups.

IEnumerable<KeyValuePair<string, string>> config

The configuration.

Fields

FallbackTypeConfig

Configuration property name for the subject name strategy fallback type.

Declaration
public const string FallbackTypeConfig = "subject.name.strategy.fallback.type"
Field Value
Type Description
string

KafkaClusterIdConfig

Configuration property name for the Kafka cluster ID.

Declaration
public const string KafkaClusterIdConfig = "subject.name.strategy.kafka.cluster.id"
Field Value
Type Description
string

NamespaceWildcard

Wildcard value for resource namespace.

Declaration
public const string NamespaceWildcard = "-"
Field Value
Type Description
string

Methods

GetSubjectNameAsync(SerializationContext, string)

Asynchronously gets the subject name for the given serialization context and record type.

Declaration
public Task<string> GetSubjectNameAsync(SerializationContext context, string recordType)
Parameters
Type Name Description
SerializationContext context

The serialization context.

string recordType

The type name of the data being written.

Returns
Type Description
Task<string>

A task that resolves to the subject name.

SetClusterIdResolver(Func<Task<string>>)

EXPERIMENTAL: subject to change or removal.

Supply a resolver for the id of the Kafka cluster the client is connected to, to be used as the resource namespace when looking up associations.

The resolver is only invoked when an association is looked up, never during construction, so constructing the client never waits on a broker. Subject names are cached per topic, so lookups - and hence resolver invocations - are rare. A cluster id specified via KafkaClusterIdConfig always wins; otherwise the most recently supplied resolver is used.

The resolver is bound to the client that supplied it and fails once that client is disposed, so a serde using this strategy must not outlive the producer or consumer it was handed to.

Declaration
public void SetClusterIdResolver(Func<Task<string>> clusterIdResolver)
Parameters
Type Name Description
Func<Task<string>> clusterIdResolver

Resolves the Kafka cluster id, returning a task that completes with null if it cannot be resolved.

In this article