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
| Improve this doc View sourceConnect(MqttClientOptions, MockedMqttClient)
Connects the specified client.
Declaration
void Connect(MqttClientOptions clientOptions, MockedMqttClient mockedMqttClient)
Parameters
Type | Name | Description |
---|---|---|
MqttClientOptions | clientOptions | The client options. |
MockedMqttClient | mockedMqttClient | The MockedMqttClient. |
Disconnect(string)
Disconnects the specified client.
Declaration
void Disconnect(string clientId)
Parameters
Type | Name | Description |
---|---|---|
string | clientId | The client identifier. |
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)
Gets the messages that have been published to the specified topic.
Declaration
IReadOnlyList<MqttApplicationMessage> GetMessages(string topic)
Parameters
Type | Name | Description |
---|---|---|
string | topic | The name of the topic. |
Returns
Type | Description |
---|---|
IReadOnlyList<MqttApplicationMessage> | The messages published to the topic. |
PublishAsync(string, MqttApplicationMessage, MqttClientOptions)
Publishes a message.
Declaration
Task PublishAsync(string clientId, MqttApplicationMessage message, MqttClientOptions clientOptions)
Parameters
Type | Name | Description |
---|---|---|
string | clientId | The client identifier. |
MqttApplicationMessage | message | The MQTTnet.MqttApplicationMessage to be published. |
MqttClientOptions | clientOptions | The MQTTnet.Client.MqttClientOptions of the producing MQTTnet.Client.MqttClient. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
Subscribe(string, IReadOnlyCollection<string>)
Subscribes the specified client to the specified topics.
Declaration
void Subscribe(string clientId, IReadOnlyCollection<string> topics)
Parameters
Type | Name | Description |
---|---|---|
string | clientId | The client identifier. |
IReadOnlyCollection<string> | topics | The name of the topics or the topic filter strings. |
Unsubscribe(string, IReadOnlyCollection<string>)
Unsubscribes the specified client from the specified topics.
Declaration
void Unsubscribe(string clientId, IReadOnlyCollection<string> topics)
Parameters
Type | Name | Description |
---|---|---|
string | clientId | The client identifier. |
IReadOnlyCollection<string> | topics | The name of the topics or the topic filter strings. |
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. |