Interface IInMemoryMqttBroker
A mocked MQTT broker where the messages are just exchanged 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.Mqtt.Mocks
Assembly: Silverback.Integration.MQTT.Testing.dll
Syntax
public interface IInMemoryMqttBroker
Methods
Connect(MockedMqttClient)
Connects the specified client.
Declaration
void Connect(MockedMqttClient client)
Parameters
| Type | Name | Description |
|---|---|---|
| MockedMqttClient | client | The client. |
Disconnect(MockedMqttClient)
Disconnects the specified client.
Declaration
void Disconnect(MockedMqttClient client)
Parameters
| Type | Name | Description |
|---|---|---|
| MockedMqttClient | client | The client. |
GetClientSession(string)
Gets the IClientSession of the specified client.
Declaration
IClientSession GetClientSession(string clientId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | clientId | The client id. |
Returns
| Type | Description |
|---|---|
| IClientSession | The IClientSession. |
GetMessages(string, string?)
Gets the messages that have been published to the specified topic.
Declaration
IReadOnlyList<MqttApplicationMessage> GetMessages(string topic, string? server = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | topic | The topic. |
| string | server | The server name used to identify the target broker. This must be specified when testing with multiple brokers. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<MqttApplicationMessage> | The messages published to the topic. |
PublishAsync(MockedMqttClient, MqttApplicationMessage, MqttClientOptions)
Publishes a message.
Declaration
ValueTask PublishAsync(MockedMqttClient client, MqttApplicationMessage message, MqttClientOptions clientOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| MockedMqttClient | client | The client. |
| MqttApplicationMessage | message | The MQTTnet.MqttApplicationMessage to be published. |
| MqttClientOptions | clientOptions | The MQTTnet.MqttClientOptions of the producing MQTTnet.MqttClient. |
Returns
| Type | Description |
|---|---|
| ValueTask | A Task representing the asynchronous operation. |
Subscribe(MockedMqttClient, IReadOnlyCollection<string>)
Subscribes the specified client to the specified topics.
Declaration
void Subscribe(MockedMqttClient client, IReadOnlyCollection<string> topics)
Parameters
| Type | Name | Description |
|---|---|---|
| MockedMqttClient | client | The client. |
| IReadOnlyCollection<string> | topics | The name of the topics or the topic filter strings. |
Unsubscribe(MockedMqttClient, IReadOnlyCollection<string>)
Unsubscribes the specified client from the specified topics.
Declaration
void Unsubscribe(MockedMqttClient client, IReadOnlyCollection<string> topics)
Parameters
| Type | Name | Description |
|---|---|---|
| MockedMqttClient | client | The client. |
| IReadOnlyCollection<string> | topics | The name of the topics or the topic filter strings. |
WaitUntilAllMessagesAreConsumedAsync(IReadOnlyCollection<string>, CancellationToken)
Returns a Task that completes when all messages routed to the consumers have been processed and committed.
Declaration
Task 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 |
|---|---|
| Task | A Task that completes when all messages have been processed. |