confluent-kafka-dotnet
Show / Hide Table of Contents

Interface IClusterIdAware

EXPERIMENTAL: subject to change or removal.

Implemented by serializers and deserializers that can make use of the id of the Kafka cluster the client is connected to.

A producer or consumer does not resolve the cluster id itself. During construction it hands each serializer or deserializer a resolver, via SetClusterIdResolver(Func<Task<string>>), which the serde invokes whenever it actually needs the id. Resolving the id requires the client to have reached a broker, which is not always possible during construction - an OAUTHBEARER token refresh callback, for instance, is only served from the poll loop - so deferring it keeps construction from blocking.

This interface is deliberately separate from ISerializer<T> and friends: those are implemented by application code, so adding members to them would be a breaking change. Use the SetClusterIdResolver extension methods to hand a resolver to an arbitrary serializer or deserializer.

Namespace: Confluent.Kafka
Assembly: Confluent.Kafka.dll
Syntax
public interface IClusterIdAware

Methods

SetClusterIdResolver(Func<Task<string>>)

Supply a resolver for the id of the Kafka cluster the client is connected to.

The resolver returns a task that completes once the client has reached a broker, with null if it cannot do so within the client's timeout; invoking it never blocks the caller. Concurrent invocations share a single resolution. Implementations are expected to invoke it lazily, only when the id is actually needed.

The resolver is bound to the client that supplied it, and throws ObjectDisposedException once that client has been disposed. A serializer or deserializer handed to a producer or consumer must therefore not be used after that client is disposed, unless the cluster id it needs was specified via configuration.

A serializer or deserializer instance holds a single resolver. If one instance is shared by several clients, the resolver supplied last replaces the earlier ones, so every client sharing the instance resolves the cluster id of the last client it was handed to. Do not share an instance between clients connected to different clusters; let the client creates the serde instance through the builder.

Implementations must ignore the resolver when the cluster id is not relevant to their configuration, or when it was specified explicitly via configuration, so that a configured cluster id is never overwritten.

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

Resolves the Kafka cluster id.

In this article