Skip to content

Connection

Namespace: MQTT_Receiver_Worker.MQTT

Handles MQTT broker connection and message processing.
Establishes a connection to the MQTT broker, subscribes to topics,
and processes incoming temperature sensor messages.

public class Connection : MQTT_Receiver_Worker.MQTT.Interfaces.IConnection

Inheritance ObjectConnection

Implements IConnection

Properties

IsConnected

Gets a value indicating whether the MQTT client is currently connected.

public bool IsConnected { get; }

Property Value

Boolean

Constructors

Connection(ILogger<Connection>, IServiceProvider, IConfiguration)

Initializes a new instance of the Connection class.

public Connection(ILogger<Connection> logger, IServiceProvider serviceProvider, IConfiguration configuration)

Parameters

logger ILogger<Connection>

Logger for recording connection events

serviceProvider IServiceProvider

configuration IConfiguration

Configuration for MQTT settings

Methods

DisconnectAsync()

Disconnects from the MQTT broker.

public Task DisconnectAsync()

Returns

A task that represents the asynchronous operation.

GetConnectionAsync()

Establishes a connection to the MQTT broker and configures message handlers.

public Task<IMqttClient> GetConnectionAsync()

Returns

A task that represents the asynchronous operation. The task result contains the connected MQTT client, or null if connection failed.

TryConnectAsync()

Attempts to connect to the MQTT broker.

public Task<Boolean> TryConnectAsync()

Returns

A task that represents the asynchronous operation. The task result indicates whether the connection was successful.