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

IsRebalanceScheduled

Gets a value indicating whether a rebalance has been scheduled.

bool IsRebalanceScheduled { get; }

Property Value

bool

IsRebalancing

Gets a value indicating whether a rebalance is being performed.

bool IsRebalancing { get; }

Property Value

bool

Methods

Assign(IMockedConfluentConsumer, IEnumerable<TopicPartition>)

Assigns the specified partitions to the consumer.

void Assign(IMockedConfluentConsumer consumer, IEnumerable<TopicPartition> partitions)

Parameters

consumer IMockedConfluentConsumer

The IMockedConfluentConsumer instance.

partitions IEnumerable<TopicPartition>

The partitions.

Commit(IEnumerable<TopicPartitionOffset>)

Commits the specified offsets.

void Commit(IEnumerable<TopicPartitionOffset> offsets)

Parameters

offsets IEnumerable<TopicPartitionOffset>

The offsets to be committed.

GetAssignment(IMockedConfluentConsumer)

Gets partition assignment for the specified consumer.

IReadOnlyCollection<TopicPartition> GetAssignment(IMockedConfluentConsumer consumer)

Parameters

consumer IMockedConfluentConsumer

The consumer.

Returns

IReadOnlyCollection<TopicPartition>

The partitions currently assigned to the consumer.

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.

RebalanceAsync()

Exectues a rebalance and causes all assignments to be revoked and reassigned.

Task<RebalanceResult> RebalanceAsync()

Returns

Task<RebalanceResult>

A Task<TResult> representing the asynchronous operation. The task result contains the partitions that have been revoked and assigned.

Remove(IMockedConfluentConsumer)

Removes the consumer from the group.

void Remove(IMockedConfluentConsumer consumer)

Parameters

consumer IMockedConfluentConsumer

The IMockedConfluentConsumer instance.

Remarks

This method is called when the IMockedConfluentConsumer is closed or disposed.

ScheduleRebalance()

Initializes a rebalance and causes all assignments to be revoked and reassigned.

void ScheduleRebalance()

Subscribe(IMockedConfluentConsumer, IEnumerable<string>)

Subscribes the consumer to the specified topics.

void Subscribe(IMockedConfluentConsumer consumer, IEnumerable<string> topics)

Parameters

consumer IMockedConfluentConsumer

The IMockedConfluentConsumer instance.

topics IEnumerable<string>

The topics to be subscribed.

Unassign(IMockedConfluentConsumer)

Removes the partitions assignment for the specified consumer.

void Unassign(IMockedConfluentConsumer consumer)

Parameters

consumer IMockedConfluentConsumer

The IMockedConfluentConsumer instance.

Unsubscribe(IMockedConfluentConsumer)

Unsubscribes the consumer from all topics.

void Unsubscribe(IMockedConfluentConsumer consumer)

Parameters

consumer IMockedConfluentConsumer

The IMockedConfluentConsumer instance.

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.