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
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
IsRebalanceScheduled
Gets a value indicating whether a rebalance has been scheduled.
bool IsRebalanceScheduled { get; }
Property Value
IsRebalancing
Gets a value indicating whether a rebalance is being performed.
bool IsRebalancing { get; }
Property Value
Methods
Assign(IMockedConfluentConsumer, IEnumerable<TopicPartition>)
Assigns the specified partitions to the consumer.
void Assign(IMockedConfluentConsumer consumer, IEnumerable<TopicPartition> partitions)
Parameters
consumerIMockedConfluentConsumerThe IMockedConfluentConsumer instance.
partitionsIEnumerable<TopicPartition>The partitions.
Commit(IEnumerable<TopicPartitionOffset>)
Commits the specified offsets.
void Commit(IEnumerable<TopicPartitionOffset> offsets)
Parameters
offsetsIEnumerable<TopicPartitionOffset>The offsets to be committed.
GetAssignment(IMockedConfluentConsumer)
Gets partition assignment for the specified consumer.
IReadOnlyCollection<TopicPartition> GetAssignment(IMockedConfluentConsumer consumer)
Parameters
consumerIMockedConfluentConsumerThe 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
topicPartitionTopicPartitionThe topic partition.
Returns
- TopicPartitionOffset
The latest committed Confluent.Kafka.Offset for the topic partition, or
nullif 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
topicstringThe 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
consumerIMockedConfluentConsumerThe 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
consumerIMockedConfluentConsumerThe IMockedConfluentConsumer instance.
topicsIEnumerable<string>The topics to be subscribed.
Unassign(IMockedConfluentConsumer)
Removes the partitions assignment for the specified consumer.
void Unassign(IMockedConfluentConsumer consumer)
Parameters
consumerIMockedConfluentConsumerThe IMockedConfluentConsumer instance.
Unsubscribe(IMockedConfluentConsumer)
Unsubscribes the consumer from all topics.
void Unsubscribe(IMockedConfluentConsumer consumer)
Parameters
consumerIMockedConfluentConsumerThe 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
topicNamesIReadOnlyCollection<string>The names of the topics to wait for. If not specified, all topics are considered.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.