Table of Contents

Interface IKafkaProducerBuilder

Namespace
Excalibur.Dispatch.Transport.Kafka
Assembly
Excalibur.Dispatch.Transport.Kafka.dll

Fluent builder interface for configuring Kafka producer settings.

public interface IKafkaProducerBuilder
Extension Methods

Examples

kafka.ConfigureProducer(producer =>
{
    producer.ClientId("my-app-producer")
            .Acks(KafkaAckLevel.All)
            .EnableIdempotence(true)
            .CompressionType(KafkaCompressionType.Snappy)
            .LingerMs(TimeSpan.FromMilliseconds(10));
});

Remarks

This interface follows the Microsoft-style fluent builder pattern. All methods return this for method chaining.

Methods

Acks(KafkaAckLevel)

Sets the acknowledgment level for message delivery.

IKafkaProducerBuilder Acks(KafkaAckLevel acks)

Parameters

acks KafkaAckLevel

The acks setting for the producer.

Returns

IKafkaProducerBuilder

The builder for fluent chaining.

Remarks

Acknowledgment levels:

  • None: Fire and forget (highest performance, lowest durability)
  • Leader: Wait for leader replica only (balanced)
  • All: Wait for all in-sync replicas (highest durability)

ClientId(string)

Sets the producer client ID.

IKafkaProducerBuilder ClientId(string clientId)

Parameters

clientId string

The client ID used to identify the producer to the broker.

Returns

IKafkaProducerBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when clientId is null, empty, or whitespace.

CompressionType(KafkaCompressionType)

Sets the compression type for messages.

IKafkaProducerBuilder CompressionType(KafkaCompressionType compressionType)

Parameters

compressionType KafkaCompressionType

The compression algorithm to use.

Returns

IKafkaProducerBuilder

The builder for fluent chaining.

EnableIdempotence(bool)

Enables or disables idempotent producer for exactly-once semantics.

IKafkaProducerBuilder EnableIdempotence(bool enable = true)

Parameters

enable bool

True to enable idempotence; otherwise, false.

Returns

IKafkaProducerBuilder

The builder for fluent chaining.

WithConfig(string, string)

Adds an additional producer configuration property.

IKafkaProducerBuilder WithConfig(string key, string value)

Parameters

key string

The configuration property key.

value string

The configuration property value.

Returns

IKafkaProducerBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when key is null, empty, or whitespace.