Interface IKafkaConsumerBuilder
Fluent builder interface for configuring Kafka consumer settings.
public interface IKafkaConsumerBuilder
- Extension Methods
Examples
kafka.ConfigureConsumer(consumer =>
{
consumer.GroupId("my-consumer-group")
.AutoOffsetReset(KafkaOffsetReset.Earliest)
.SessionTimeout(TimeSpan.FromSeconds(45))
.MaxBatchSize(100);
});
Remarks
This interface follows the Microsoft-style fluent builder pattern.
All methods return this for method chaining.
Methods
AutoOffsetReset(KafkaOffsetReset)
Sets the auto offset reset policy.
IKafkaConsumerBuilder AutoOffsetReset(KafkaOffsetReset offsetReset)
Parameters
offsetResetKafkaOffsetResetWhere to start consuming when no committed offset exists.
Returns
- IKafkaConsumerBuilder
The builder for fluent chaining.
Remarks
Offset reset policies:
- Earliest: Start from the beginning of the topic
- Latest: Start from the end (new messages only)
- None: Throw exception if no offset found
EnableAutoCommit(bool)
Enables or disables automatic offset commits.
IKafkaConsumerBuilder EnableAutoCommit(bool enable = true)
Parameters
enableboolTrue to auto-commit offsets; otherwise, false for manual commits.
Returns
- IKafkaConsumerBuilder
The builder for fluent chaining.
GroupId(string)
Sets the consumer group ID.
IKafkaConsumerBuilder GroupId(string groupId)
Parameters
groupIdstringThe consumer group identifier.
Returns
- IKafkaConsumerBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
groupIdis null, empty, or whitespace.
SessionTimeout(TimeSpan)
Sets the session timeout for detecting consumer failures.
IKafkaConsumerBuilder SessionTimeout(TimeSpan timeout)
Parameters
timeoutTimeSpanThe session timeout duration.
Returns
- IKafkaConsumerBuilder
The builder for fluent chaining.
Exceptions
- ArgumentOutOfRangeException
Thrown when
timeoutis negative or zero.
WithConfig(string, string)
Adds an additional consumer configuration property.
IKafkaConsumerBuilder WithConfig(string key, string value)
Parameters
Returns
- IKafkaConsumerBuilder
The builder for fluent chaining.
Exceptions
- ArgumentException
Thrown when
keyis null, empty, or whitespace.