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
clientMockedMqttClientThe client.
Disconnect(MockedMqttClient)
Disconnects the specified client.
void Disconnect(MockedMqttClient client)
Parameters
clientMockedMqttClientThe client.
GetClientSession(string)
Gets the IClientSession of the specified client.
IClientSession GetClientSession(string clientId)
Parameters
clientIdstringThe client id.
Returns
GetMessages(string, string?)
Gets the messages that have been published to the specified topic.
IReadOnlyList<MqttApplicationMessage> GetMessages(string topic, string? server = null)
Parameters
topicstringThe topic.
serverstringThe 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
clientMockedMqttClientThe client.
messageMqttApplicationMessageThe MQTTnet.MqttApplicationMessage to be published.
clientOptionsMqttClientOptionsThe MQTTnet.MqttClientOptions of the producing MQTTnet.MqttClient.
Returns
Subscribe(MockedMqttClient, IReadOnlyCollection<string>)
Subscribes the specified client to the specified topics.
void Subscribe(MockedMqttClient client, IReadOnlyCollection<string> topics)
Parameters
clientMockedMqttClientThe client.
topicsIReadOnlyCollection<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
clientMockedMqttClientThe client.
topicsIReadOnlyCollection<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
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.