Table of Contents

Interface IInMemoryMqttBroker

Namespace
Silverback.Messaging.Broker.Mqtt.Mocks
Assembly
Silverback.Integration.MQTT.Testing.dll

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.

public interface IInMemoryMqttBroker

Methods

Connect(MockedMqttClient)

Connects the specified client.

void Connect(MockedMqttClient client)

Parameters

client MockedMqttClient

The client.

Disconnect(MockedMqttClient)

Disconnects the specified client.

void Disconnect(MockedMqttClient client)

Parameters

client MockedMqttClient

The client.

GetClientSession(string)

Gets the IClientSession of the specified client.

IClientSession GetClientSession(string clientId)

Parameters

clientId string

The client id.

Returns

IClientSession

The IClientSession.

GetMessages(string, string?)

Gets the messages that have been published to the specified topic.

IReadOnlyList<MqttApplicationMessage> GetMessages(string topic, string? server = null)

Parameters

topic string

The topic.

server string

The server name used to identify the target broker. This must be specified when testing with multiple brokers.

Returns

IReadOnlyList<MqttApplicationMessage>

The messages published to the topic.

PublishAsync(MockedMqttClient, MqttApplicationMessage, MqttClientOptions)

Publishes a message.

ValueTask PublishAsync(MockedMqttClient client, MqttApplicationMessage message, MqttClientOptions clientOptions)

Parameters

client MockedMqttClient

The client.

message MqttApplicationMessage

The MQTTnet.MqttApplicationMessage to be published.

clientOptions MqttClientOptions

The MQTTnet.MqttClientOptions of the producing MQTTnet.MqttClient.

Returns

ValueTask

A Task representing the asynchronous operation.

Subscribe(MockedMqttClient, IReadOnlyCollection<string>)

Subscribes the specified client to the specified topics.

void Subscribe(MockedMqttClient client, IReadOnlyCollection<string> topics)

Parameters

client MockedMqttClient

The client.

topics IReadOnlyCollection<string>

The name of the topics or the topic filter strings.

Unsubscribe(MockedMqttClient, IReadOnlyCollection<string>)

Unsubscribes the specified client from the specified topics.

void Unsubscribe(MockedMqttClient client, IReadOnlyCollection<string> topics)

Parameters

client MockedMqttClient

The client.

topics IReadOnlyCollection<string>

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.

Task 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

Task

A Task that completes when all messages have been processed.