Class MqttConnector
This class implements the IMqttConnectable
interface and uses the The library MQTTnet internally.
Inheritance
Namespace: TeleScope.Connectors.Mqtt
Assembly: TeleScope.Connectors.Mqtt.dll
Syntax
public class MqttConnector : object, IMqttConnectable, IConnectable, IAsyncConnectable
Constructors
| Improve this Doc View SourceMqttConnector(MqttSetup)
The constructor instanciates the internal logging, stores the setup configuration and prepares the internal mqtt client.
Declaration
public MqttConnector(MqttSetup setup)
Parameters
Type | Name | Description |
---|---|---|
MqttSetup | setup | The setup for the mqtt client. |
Properties
| Improve this Doc View SourceIsConnected
Gets the state, if the connection is established or not.
Declaration
public bool IsConnected { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceConnect()
Connects the internal Mqtt client with the prepared options and invokes the Failed event if an error occures.
Declaration
public IConnectable Connect()
Returns
Type | Description |
---|---|
IConnectable | The calling instance. |
ConnectAsync()
Connects the internal Mqtt client asynchronously with the prepared options and invokes the Failed event if an error occures.
Declaration
public Task ConnectAsync()
Returns
Type | Description |
---|---|
Task | The executing task. |
Disconnect()
Disconnects the internal Mqtt client.
Declaration
public IConnectable Disconnect()
Returns
Type | Description |
---|---|
IConnectable | The calling instance. |
DisconnectAsync()
Disconnects the internal Mqtt client asynchronously.
Declaration
public Task DisconnectAsync()
Returns
Type | Description |
---|---|
Task | The executing task. |
PublishAsync(String, String)
Sends a message string asynchronously to a given broker.
Declaration
public Task PublishAsync(string topic, string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | topic | The topic of the message. |
System.String | message | The message that will be sent. |
Returns
Type | Description |
---|---|
Task | The executing task. |
PublishAsync(String, String, Int32)
Sends a message string asynchronously to a given broker.
Declaration
public Task PublishAsync(string topic, string message, int qualityOfService)
Parameters
Type | Name | Description |
---|---|---|
System.String | topic | The topic of the message. |
System.String | message | The message that will be sent. |
System.Int32 | qualityOfService | The level of quality that will be used for sending. |
Returns
Type | Description |
---|---|
Task | The executing task. |
Subscribe(String)
Subscribes to a new topic that the client will listen to.
Declaration
public IMqttConnectable Subscribe(string topic)
Parameters
Type | Name | Description |
---|---|---|
System.String | topic | The topic of interest. |
Returns
Type | Description |
---|---|
IMqttConnectable | The calling instance. |
Unsubscribe(String)
Unsubscribes from a topic that the client will no longer listen to.
Declaration
public IMqttConnectable Unsubscribe(string topic)
Parameters
Type | Name | Description |
---|---|---|
System.String | topic | The topic that will be removed. |
Returns
Type | Description |
---|---|
IMqttConnectable | The calling instance. |
Events
| Improve this Doc View SourceCompleted
The event is invoked when the PublishAsync
methods have finished successfully.
Declaration
public event ConnectorCompletedEventHandler Completed
Event Type
Type | Description |
---|---|
ConnectorCompletedEventHandler |
Connected
The event is invoked when the Connect
method has finished successfully.
Declaration
public event ConnectorEventHandler Connected
Event Type
Type | Description |
---|---|
ConnectorEventHandler |
Disconnected
The event is invoked when the Disconnect
method has finished successfully.
Declaration
public event ConnectorEventHandler Disconnected
Event Type
Type | Description |
---|---|
ConnectorEventHandler |
Failed
The event is invoked when any method or action has finished with a failure.
Declaration
public event ConnectorFailedEventHandler Failed
Event Type
Type | Description |
---|---|
ConnectorFailedEventHandler |
MessageReceived
The event is invoked when the subscription to a topic has received a message.
Declaration
public event MqttConnectorEventHandler MessageReceived
Event Type
Type | Description |
---|---|
MqttConnectorEventHandler |