Interface IMockedConsumerGroup
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.
Namespace: Silverback.Messaging.Broker.Kafka.Mocks
Assembly: Silverback.Integration.Kafka.Testing.dll
Syntax
public interface IMockedConsumerGroup
Properties
BootstrapServers
Gets the bootstrap servers string used to identify the target broker.
Declaration
string BootstrapServers { get; }
Property Value
| Type | Description |
|---|---|
| string |
CommittedOffsets
Gets the latest committed Confluent.Kafka.Offset for each topic partition.
Declaration
IReadOnlyCollection<TopicPartitionOffset> CommittedOffsets { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyCollection<TopicPartitionOffset> | The collection containing the latest Confluent.Kafka.Offset for each topic partition. |
GroupId
Gets the consumer group id.
Declaration
string GroupId { get; }
Property Value
| Type | Description |
|---|---|
| string |
IsRebalanceScheduled
Gets a value indicating whether a rebalance has been scheduled.
Declaration
bool IsRebalanceScheduled { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsRebalancing
Gets a value indicating whether a rebalance is being performed.
Declaration
bool IsRebalancing { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Assign(IMockedConfluentConsumer, IEnumerable<TopicPartition>)
Assigns the specified partitions to the consumer.
Declaration
void Assign(IMockedConfluentConsumer consumer, IEnumerable<TopicPartition> partitions)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
| IEnumerable<TopicPartition> | partitions | The partitions. |
Commit(IEnumerable<TopicPartitionOffset>)
Commits the specified offsets.
Declaration
void Commit(IEnumerable<TopicPartitionOffset> offsets)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<TopicPartitionOffset> | offsets | The offsets to be committed. |
GetAssignment(IMockedConfluentConsumer)
Gets partition assignment for the specified consumer.
Declaration
IReadOnlyCollection<TopicPartition> GetAssignment(IMockedConfluentConsumer consumer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | The consumer. |
Returns
| Type | Description |
|---|---|
| IReadOnlyCollection<TopicPartition> | The partitions currently assigned to the consumer. |
GetCommittedOffset(TopicPartition)
Gets the latest committed Confluent.Kafka.Offset for the specified topic partition.
Declaration
TopicPartitionOffset? GetCommittedOffset(TopicPartition topicPartition)
Parameters
| Type | Name | Description |
|---|---|---|
| TopicPartition | topicPartition | The topic partition. |
Returns
| Type | Description |
|---|---|
| TopicPartitionOffset | The latest committed Confluent.Kafka.Offset for the topic partition, or |
GetCommittedOffsetsCount(string)
Gets the total number of committed offsets. This number is usually equal to the number of consumed messages.
Declaration
long GetCommittedOffsetsCount(string topic)
Parameters
| Type | Name | Description |
|---|---|---|
| string | topic | The topic. |
Returns
| Type | Description |
|---|---|
| long | The number of committed offsets. |
RebalanceAsync()
Exectues a rebalance and causes all assignments to be revoked and reassigned.
Declaration
Task<RebalanceResult> RebalanceAsync()
Returns
| Type | Description |
|---|---|
| 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.
Declaration
void Remove(IMockedConfluentConsumer consumer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | 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.
Declaration
void ScheduleRebalance()
Subscribe(IMockedConfluentConsumer, IEnumerable<string>)
Subscribes the consumer to the specified topics.
Declaration
void Subscribe(IMockedConfluentConsumer consumer, IEnumerable<string> topics)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
| IEnumerable<string> | topics | The topics to be subscribed. |
Unassign(IMockedConfluentConsumer)
Removes the partitions assignment for the specified consumer.
Declaration
void Unassign(IMockedConfluentConsumer consumer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
Unsubscribe(IMockedConfluentConsumer)
Unsubscribes the consumer from all topics.
Declaration
void Unsubscribe(IMockedConfluentConsumer consumer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string>, CancellationToken)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
ValueTask WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string> topicNames, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyCollection<string> | topicNames | 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
| Type | Description |
|---|---|
| ValueTask | A ValueTask that completes when all messages have been processed. |