Inherits: IMessageQueueConnection, IReferenceable, IConfigurable, IOpenable
Description
The MqttConnection class allows you to create MQTT connections using the default driver.
Important points
By defining a connection and sharing it through multiple message queues you can reduce the number of used connections.
Configuration parameters
- client_id: (optional) name of the client id
 - connection(s):
- discovery_key: (optional) key to retrieve the connection from IDiscovery
 - host: host name or IP address
 - port: port number
 - uri: resource URI or connection string with all parameters in it
 
 - credential(s):
- store_key: (optional) key to retrieve the credentials from ICredentialStore
 - username: username
 - password: user’s password
 
 - options:
- retry_connect: (optional) turns on/off automated reconnect when connection is lost (default: true)
 - connect_timeout: (optional) number of milliseconds to wait for connection (default: 30000)
 - reconnect_timeout: (optional) number of milliseconds to wait on each reconnection attempt (default: 1000)
 - keepalive_timeout: (optional) number of milliseconds to ping broker while inactive (default: 3000)
 
 
References
- *:logger:*:*:1.0 - (optional) ILogger components to pass log messages
 - *:counters:*:*:1.0 - (optional) [ICounters]ICounters components to pass collected measurements
 - *:discovery:*:*:1.0 - (optional) IDiscovery services
 - *:credential-store:*:*:1.0 (optional) credential stores to resolve credentials
 
Constructors
Creates a new instance of the connection component.
publicMqttConnection()
Fields
Instance methods
CheckOpen
Checks if the connection is open.
Raises an error if the connection is closed.
privatevoid CheckOpen()
CloseAsync
Closes a component and frees used resources.
publicTask CloseAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
 
Configure
Configures the component by passing its configuration parameters.
publicvoid Configure([ConfigParams](../../../commons/config/config_params config)
- config: ConfigParams - configuration parameters to be set.
 
CreateQueueAsync
Creates a message queue. If the connection doesn’t support this function, it exists without error.
publicTask CreateQueueAsync(string name)
- name: string - name of the queue to be created.
 
DeleteQueueAsync
Deletes a message queue. If the connection doesn’t support this function, it exists without error.
publicTask DeleteQueueAsync(string name)
- name: string - name of the queue to be deleted.
 
GetConnection
Gets the connection.
publicIMqttClient GetConnection()
- returns: IMqttClient - connection to an MQTT broker.
 
IsOpen
Checks if the component is open.
publicbool IsOpen()
- returns: bool - true if the component is open and false otherwise.
 
OpenAsync
Opens the component.
publicTask OpenAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
 
PublishAsync
Publish a message to a specified topic.
publicTask PublishAsync(string topic, MqttApplicationMessage message)
- topic: string - topic name
 - message: MqttApplicationMessage - message to be published
 
ReadQueueNamesAsync
Reads a list of registered queue names. If the connection doesn’t support this function, it returns an empty list.
publicTask<List<string>> ReadQueueNamesAsync()
- returns: Task<List<string>> - queue names.
 
SetReferences
Sets references to dependent components.
publicvoid SetReferences(IReferences references)
- references: IReferences - references to locate the component dependencies.
 
SubscribeAsync
Subscribes to a topic
publicTask SubscribeAsync(string topic, MqttQualityOfServiceLevel qos, IMqttMessageListener listener)
- topic: string - topic name
 - qos: MqttQualityOfServiceLevel - quality of service level
 - listener: IMqttMessageListener - message listener
 
UnsubscribeAsync
Unsubscribes from a previously subscribed topic.
publicTask UnsubscribeAsync(string topic, IMqttMessageListener listener)
- topic: string - topic name
 - listener: IMqttMessageListener - message listener