Table of Contents

Class OrderedAckMqttClient

Namespace
Azure.Iot.Operations.Mqtt
Assembly
Azure.Iot.Operations.Mqtt.dll

A simple pass-through implementation of the IMqttPubSubClient interface that uses MQTTNet as the underlying MQTT client.

public class OrderedAckMqttClient : IMqttClient, IMqttPubSubClient, IAsyncDisposable
Inheritance
OrderedAckMqttClient
Implements
Derived
Inherited Members

Remarks

This client has no built-in retry logic or connection handling. It does add ACK ordering support, though.

Constructors

OrderedAckMqttClient(IMqttClient, OrderedAckMqttClientOptions?)

public OrderedAckMqttClient(IMqttClient mqttNetClient, OrderedAckMqttClientOptions? clientOptions = null)

Parameters

mqttNetClient IMqttClient
clientOptions OrderedAckMqttClientOptions

Properties

ClientId

Returns the client Id used by this client.

public string? ClientId { get; }

Property Value

string

Remarks

If a client Id has not been assigned yet by the user or by the broker, this value is null.

IsConnected

Get if this MQTT client is currently connected or not.

public bool IsConnected { get; }

Property Value

bool

ProtocolVersion

The version of the MQTT protocol that this client is using.

public MqttProtocolVersion ProtocolVersion { get; }

Property Value

MqttProtocolVersion

UnderlyingMqttClient

The MQTT client used by this client to handle all MQTT operations.

public IMqttClient UnderlyingMqttClient { get; }

Property Value

IMqttClient

Methods

ConnectAsync(MqttConnectionSettings, CancellationToken)

Connect this client to the MQTT broker configured in the provided connection settings.

public virtual Task<MqttClientConnectResult> ConnectAsync(MqttConnectionSettings settings, CancellationToken cancellationToken = default)

Parameters

settings MqttConnectionSettings

The details about the MQTT broker to connect to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<MqttClientConnectResult>

The CONNACK returned by the MQTT broker.

ConnectAsync(MqttClientOptions, CancellationToken)

Connect this client to the MQTT broker configured in the provided connection options.

public virtual Task<MqttClientConnectResult> ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken = default)

Parameters

options MqttClientOptions

The details about the MQTT broker to connect to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<MqttClientConnectResult>

The CONNACK returned by the MQTT broker.

DisconnectAsync(MqttClientDisconnectOptions?, CancellationToken)

Disconnect this client from the MQTT broker.

public virtual Task DisconnectAsync(MqttClientDisconnectOptions? options = null, CancellationToken cancellationToken = default)

Parameters

options MqttClientDisconnectOptions

The optional parameters to include in the DISCONNECT request.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public virtual ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeAsync(bool)

public virtual ValueTask DisposeAsync(bool disposing)

Parameters

disposing bool

Returns

ValueTask

GetMaximumPacketSize()

Get the maximum packet size that this client can send.

public uint GetMaximumPacketSize()

Returns

uint

The maximum packet size.

PublishAsync(MqttApplicationMessage, CancellationToken)

Publish a message to the MQTT broker.

public virtual Task<MqttClientPublishResult> PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken = default)

Parameters

applicationMessage MqttApplicationMessage

The message to publish

cancellationToken CancellationToken

Cancellation token.

Returns

Task<MqttClientPublishResult>

The result of the publish.

Remarks

The behavior of publishing when the MQTT client is disconnected will vary depending on the implementation.

ReconnectAsync(CancellationToken)

Reconnect the client if it is disconnected. This will use the MqttClientOptions last provided when connecting.

public Task ReconnectAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task

SendEnhancedAuthenticationExchangeDataAsync(MqttEnhancedAuthenticationExchangeData, CancellationToken)

Send additional authentication data. May be done on an active connection.

public Task SendEnhancedAuthenticationExchangeDataAsync(MqttEnhancedAuthenticationExchangeData data, CancellationToken cancellationToken = default)

Parameters

data MqttEnhancedAuthenticationExchangeData

The authentication data to send.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

SubscribeAsync(MqttClientSubscribeOptions, CancellationToken)

Subscribe to a topic on the MQTT broker.

public virtual Task<MqttClientSubscribeResult> SubscribeAsync(MqttClientSubscribeOptions options, CancellationToken cancellationToken = default)

Parameters

options MqttClientSubscribeOptions

The details of the subscribe.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<MqttClientSubscribeResult>

The MQTT broker's response.

Remarks

The behavior of subscribing when the MQTT client is disconnected will vary depending on the implementation.

UnsubscribeAsync(MqttClientUnsubscribeOptions, CancellationToken)

Unsubscribe from a topic on the MQTT broker.

public virtual Task<MqttClientUnsubscribeResult> UnsubscribeAsync(MqttClientUnsubscribeOptions options, CancellationToken cancellationToken = default)

Parameters

options MqttClientUnsubscribeOptions

The details of the unsubscribe request.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<MqttClientUnsubscribeResult>

The MQTT broker's response.

Remarks

The behavior of unsubscribing when the MQTT client is disconnected will vary depending on the implementation.

Events

ApplicationMessageReceivedAsync

The event that notifies you when this client receives a PUBLISH from the MQTT broker.

public event Func<MqttApplicationMessageReceivedEventArgs, Task>? ApplicationMessageReceivedAsync

Event Type

Func<MqttApplicationMessageReceivedEventArgs, Task>

Remarks

Users are responsible for acknowledging each received PUBLISH. Users must either automatically acknowledge the message by opting into automatically sending the acknowledgement by setting the AutoAcknowledge flag, or they can manually acknowledge the PUBLISH by invoking AcknowledgeAsync(CancellationToken).

Note that this client sends PUBLISH acknowledgements in the order that the corresponding PUBLISH packets were received, so failing to acknowledge a PUBLISH will block sending acknowledgements for all subsequent PUBLISH packets received.

ConnectedAsync

An event that executes every time this client is connected.

public event Func<MqttClientConnectedEventArgs, Task>? ConnectedAsync

Event Type

Func<MqttClientConnectedEventArgs, Task>

DisconnectedAsync

An event that executes every time this client is disconnected.

public event Func<MqttClientDisconnectedEventArgs, Task>? DisconnectedAsync

Event Type

Func<MqttClientDisconnectedEventArgs, Task>