Interface IKafkaProducerBuilder
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
acksKafkaAckLevelThe 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
clientIdstringThe client ID used to identify the producer to the broker.
Returns
- IKafkaProducerBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
clientIdis null, empty, or whitespace.
CompressionType(KafkaCompressionType)
Sets the compression type for messages.
IKafkaProducerBuilder CompressionType(KafkaCompressionType compressionType)
Parameters
compressionTypeKafkaCompressionTypeThe 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
enableboolTrue 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
Returns
- IKafkaProducerBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
keyis null, empty, or whitespace.