Interface IInMemoryTopic
A mocked topic where the messages are just stored in memory. 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 IInMemoryTopic
Properties
| Improve this doc View sourceBootstrapServers
Gets the bootstrap servers string used to identify the target broker.
Declaration
string BootstrapServers { get; }
Property Value
Type | Description |
---|---|
string |
MessagesCount
Gets the total number of messages written into all the partitions of the topic.
Declaration
int MessagesCount { get; }
Property Value
Type | Description |
---|---|
int |
Name
Gets the topic name.
Declaration
string Name { get; }
Property Value
Type | Description |
---|---|
string |
Partitions
Gets the partitions in the topic.
Declaration
IReadOnlyList<IInMemoryPartition> Partitions { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IInMemoryPartition> |
Methods
| Improve this doc View sourceAbortTransaction(Guid)
Aborts the transaction.
Declaration
void AbortTransaction(Guid transactionalUniqueId)
Parameters
Type | Name | Description |
---|---|---|
Guid | transactionalUniqueId | The transactional unique identifier. |
Assign(IMockedConfluentConsumer, Partition)
Assigns the specified partition to the consumer.
Declaration
void Assign(IMockedConfluentConsumer consumer, Partition partition)
Parameters
Type | Name | Description |
---|---|---|
IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
Partition | partition | The partition. |
Commit(string, IEnumerable<TopicPartitionOffset>)
Commits the offsets of the specified consumer group.
Declaration
IReadOnlyCollection<TopicPartitionOffset> Commit(string groupId, IEnumerable<TopicPartitionOffset> partitionOffsets)
Parameters
Type | Name | Description |
---|---|---|
string | groupId | The consumer group id. |
IEnumerable<TopicPartitionOffset> | partitionOffsets | The offsets to be committed. |
Returns
Type | Description |
---|---|
IReadOnlyCollection<TopicPartitionOffset> | The actual committed offsets. |
CommitTransaction(Guid)
Commits the transaction.
Declaration
void CommitTransaction(Guid transactionalUniqueId)
Parameters
Type | Name | Description |
---|---|---|
Guid | transactionalUniqueId | The transactional unique identifier. |
EnsurePartitionsAssigned(IMockedConfluentConsumer, TimeSpan, CancellationToken)
Ensures that a partition assignment has been given to the specified consumer, otherwise triggers the assignment process.
Declaration
void EnsurePartitionsAssigned(IMockedConfluentConsumer consumer, TimeSpan assignmentDelay, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IMockedConfluentConsumer | consumer | The consumer. |
TimeSpan | assignmentDelay | The delay to be applied before assigning the partitions. |
CancellationToken | cancellationToken | A CancellationToken to observe while waiting for the task to complete. |
GetAllMessages()
Gets all messages written into all the partitions of the topic.
Declaration
IReadOnlyList<Message<byte[]?, byte[]?>> GetAllMessages()
Returns
Type | Description |
---|---|
IReadOnlyList<Message<byte[], byte[]>> | The messages written into the topic. |
GetCommittedOffset(Partition, string)
Gets the latest committed Confluent.Kafka.Offset for the specified partition.
Declaration
Offset GetCommittedOffset(Partition partition, string groupId)
Parameters
Type | Name | Description |
---|---|---|
Partition | partition | The partition. |
string | groupId | The consumer group id. |
Returns
Type | Description |
---|---|
Offset | The latest Confluent.Kafka.Offset. |
GetCommittedOffsets(string)
Gets the latest committed Confluent.Kafka.Offset for each partition.
Declaration
IReadOnlyCollection<TopicPartitionOffset> GetCommittedOffsets(string groupId)
Parameters
Type | Name | Description |
---|---|---|
string | groupId | The consumer group id. |
Returns
Type | Description |
---|---|
IReadOnlyCollection<TopicPartitionOffset> | The collection containing the latest Confluent.Kafka.Offset for each partition. |
GetCommittedOffsetsCount(string)
Gets the number of committed offsets for the specified consumer group. This number is usually equal to the number of consumed messages.
Declaration
long GetCommittedOffsetsCount(string groupId)
Parameters
Type | Name | Description |
---|---|---|
string | groupId | The consumer group id. |
Returns
Type | Description |
---|---|
long | The number of committed offsets. |
GetFirstOffset(Partition)
Gets the Confluent.Kafka.Offset of the first message in the specified partition.
Declaration
Offset GetFirstOffset(Partition partition)
Parameters
Type | Name | Description |
---|---|---|
Partition | partition | The partition. |
Returns
Type | Description |
---|---|
Offset | The Confluent.Kafka.Offset of the first message in the partition. |
GetLastOffset(Partition)
Gets the Confluent.Kafka.Offset of the latest message written to the specified partition.
Declaration
Offset GetLastOffset(Partition partition)
Parameters
Type | Name | Description |
---|---|---|
Partition | partition | The partition. |
Returns
Type | Description |
---|---|
Offset | The Confluent.Kafka.Offset of the latest message in the partition. |
Push(int, Message<byte[]?, byte[]?>, Guid)
Writes a message to the topic.
Declaration
Offset Push(int partition, Message<byte[]?, byte[]?> message, Guid transactionalUniqueId)
Parameters
Type | Name | Description |
---|---|---|
int | partition | The index of the partition to be written to. |
Message<byte[], byte[]> | message | The message to be written. |
Guid | transactionalUniqueId | The transactional unique identifier. |
Returns
Type | Description |
---|---|
Offset | The Confluent.Kafka.Offset at which the message was written. |
Rebalance()
Simulates a rebalance and causes all assignments to be revoked and reassigned.
Declaration
void Rebalance()
Subscribe(IMockedConfluentConsumer)
Subscribes the consumer to the topic.
Declaration
void Subscribe(IMockedConfluentConsumer consumer)
Parameters
Type | Name | Description |
---|---|---|
IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
Unsubscribe(IMockedConfluentConsumer)
Unsubscribes the consumer from the topic.
Declaration
void Unsubscribe(IMockedConfluentConsumer consumer)
Parameters
Type | Name | Description |
---|---|---|
IMockedConfluentConsumer | consumer | The IMockedConfluentConsumer instance. |
WaitUntilAllMessagesAreConsumedAsync(CancellationToken)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
Task WaitUntilAllMessagesAreConsumedAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A CancellationToken to observe while waiting for the task to complete. |
Returns
Type | Description |
---|---|
Task | A Task that completes when all messages have been processed. |