Table of Contents

Interface IMockedConsumerGroup

Namespace
Silverback.Messaging.Broker.Kafka.Mocks
Assembly
Silverback.Integration.Kafka.Testing.dll

A mocked consumer group. Note that it isn't obviously possible to accurately replicate the message broker behavior, and this implementation is just intended for testing purposes.

public interface IMockedConsumerGroup

Properties

BootstrapServers

Gets the bootstrap servers string used to identify the target broker.

string BootstrapServers { get; }

Property Value

string

CommittedOffsets

Gets the latest committed Confluent.Kafka.Offset for each topic partition.

IReadOnlyCollection<TopicPartitionOffset> CommittedOffsets { get; }

Property Value

IReadOnlyCollection<TopicPartitionOffset>

The collection containing the latest Confluent.Kafka.Offset for each topic partition.

GroupId

Gets the consumer group id.

string GroupId { get; }

Property Value

string

Methods

GetCommittedOffset(TopicPartition)

Gets the latest committed Confluent.Kafka.Offset for the specified topic partition.

TopicPartitionOffset? GetCommittedOffset(TopicPartition topicPartition)

Parameters

topicPartition TopicPartition

The topic partition.

Returns

TopicPartitionOffset

The latest committed Confluent.Kafka.Offset for the topic partition, or null if no offset has been committed for this partition.

GetCommittedOffsetsCount(string)

Gets the total number of committed offsets. This number is usually equal to the number of consumed messages.

long GetCommittedOffsetsCount(string topic)

Parameters

topic string

The topic.

Returns

long

The number of committed offsets.

Rebalance()

Triggers a rebalance that will be asynchronously executed.

void Rebalance()

WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string>, CancellationToken)

Returns a Task that completes when all messages routed to the consumers have been processed and committed.

ValueTask WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string> topicNames, CancellationToken cancellationToken = default)

Parameters

topicNames IReadOnlyCollection<string>

The names of the topics to wait for. If not specified, all topics are considered.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

ValueTask

A ValueTask that completes when all messages have been processed.