Table of Contents

Interface IMqttClientWrapper

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

Wraps the underlying MQTTnet.MqttClient and handles the connection lifecycle.

public interface IMqttClientWrapper : IBrokerClient, IDisposable, IAsyncDisposable
Inherited Members

Properties

Configuration

Gets the client configuration.

MqttClientConfiguration Configuration { get; }

Property Value

MqttClientConfiguration

Connected

Gets the AsyncEvent<TArg> that is fired when the connection with the broker is established.

AsyncEvent<BrokerClient> Connected { get; }

Property Value

AsyncEvent<BrokerClient>

IsConnected

Gets a value indicating whether the client is connected with the broker.

bool IsConnected { get; }

Property Value

bool

MessageReceived

Gets the AsyncEvent<TArg> that is fired when a message is received.

AsyncEvent<MqttApplicationMessageReceivedEventArgs> MessageReceived { get; }

Property Value

AsyncEvent<MqttApplicationMessageReceivedEventArgs>

Subscribed

Gets the AsyncEvent<TArg> that is fired when the topics are successfully subscribed. It isn't fired if the broker rejects all the topic filters.

AsyncEvent<BrokerClient> Subscribed { get; }

Property Value

AsyncEvent<BrokerClient>

SubscribedTopicsFilters

Gets the subscribed topics filters, excluding the ones rejected by the broker at the last subscription.

IReadOnlyCollection<MqttTopicFilter> SubscribedTopicsFilters { get; }

Property Value

IReadOnlyCollection<MqttTopicFilter>

Methods

Produce(byte[]?, IReadOnlyCollection<MessageHeader>?, MqttProducerEndpoint, Action<IBrokerMessageIdentifier?>, Action<Exception>)

Produces the message to the specified endpoint.

void Produce(byte[]? content, IReadOnlyCollection<MessageHeader>? headers, MqttProducerEndpoint endpoint, Action<IBrokerMessageIdentifier?> onSuccess, Action<Exception> onError)

Parameters

content byte[]

The message content.

headers IReadOnlyCollection<MessageHeader>

The message headers.

endpoint MqttProducerEndpoint

The destination endpoint (topic).

onSuccess Action<IBrokerMessageIdentifier>

A callback to be invoked when the message is successfully produced.

onError Action<Exception>

A callback to be invoked when an error occurs trying to produce the message.

SubscribeAsync()

Subscribes to all configured topics and starts consuming messages.

Task SubscribeAsync()

Returns

Task

A Task representing the asynchronous operation.

UnsubscribeAsync()

Unsubscribes from the subscribed topics, excluding the topic filters rejected by the broker at the last subscription.

Task UnsubscribeAsync()

Returns

Task

A Task representing the asynchronous operation.

Remarks

The broker acknowledgment is awaited for up to the configured Timeout. The topic filters whose unsubscription is rejected by the broker are logged, without failing.