Table of Contents

Interface IKafkaConsumerBuilder

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

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

offsetReset KafkaOffsetReset

Where 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

enable bool

True 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

groupId string

The consumer group identifier.

Returns

IKafkaConsumerBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when groupId is null, empty, or whitespace.

SessionTimeout(TimeSpan)

Sets the session timeout for detecting consumer failures.

IKafkaConsumerBuilder SessionTimeout(TimeSpan timeout)

Parameters

timeout TimeSpan

The session timeout duration.

Returns

IKafkaConsumerBuilder

The builder for fluent chaining.

Exceptions

ArgumentOutOfRangeException

Thrown when timeout is negative or zero.

WithConfig(string, string)

Adds an additional consumer configuration property.

IKafkaConsumerBuilder WithConfig(string key, string value)

Parameters

key string

The configuration property key.

value string

The configuration property value.

Returns

IKafkaConsumerBuilder

The builder for fluent chaining.

Exceptions

ArgumentException

Thrown when key is null, empty, or whitespace.