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
Connected
Gets the AsyncEvent<TArg> that is fired when the connection with the broker is established.
AsyncEvent<BrokerClient> Connected { get; }
Property Value
IsConnected
Gets a value indicating whether the client is connected with the broker.
bool IsConnected { get; }
Property Value
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
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
contentbyte[]The message content.
headersIReadOnlyCollection<MessageHeader>The message headers.
endpointMqttProducerEndpointThe destination endpoint (topic).
onSuccessAction<IBrokerMessageIdentifier>A callback to be invoked when the message is successfully produced.
onErrorAction<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
UnsubscribeAsync()
Unsubscribes from the subscribed topics, excluding the topic filters rejected by the broker at the last subscription.
Task UnsubscribeAsync()
Returns
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.