MqttConnection class Null safety

Connection to MQTT message broker.

MQTT is a popular light-weight protocol to communicate IoT devices.

Configuration parameters

  • client_id: (optional) name of the client id
  • connection(s):
    • discovery_key: (optional) a 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) a key to retrieve the credentials from ICredentialStore
    • username: user name
    • password: user password
  • options:
    • retry_connect: (optional) turns on/off automated reconnect when connection is log (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)


  • :logger::*:1.0 (optional) ILogger components to pass log messages
  • :counters::*:1.0 (optional) ICounters components to pass collected measurements
  • :discovery::*:1.0 (optional) IDiscovery services to resolve connections
  • :credential-store::*:1.0 (optional) Credential stores to resolve credentials

See MessageQueue See MessagingCapabilities

Implemented types




clientId_ String
read / write
connection_ MqttServerClient?
The NATS connection pool object.
read / write
connectionResolver_ MqttConnectionResolver
The connection resolver.
read / write
connectTimeout_ int
read / write
hashCode int
The hash code for this object.
keepAliveTimeout_ int
read / write
logger_ CompositeLogger
The logger.
read / write
options_ ConfigParams
The configuration options.
read / write
reconnectTimeout_ int
read / write
retryConnect_ bool
read / write
runtimeType Type
A representation of the runtime type of the object.
subscriptions_ List<MqttSubscription>
Topic subscriptions
read / write


checkOpen() → void
Checks if connection is open
close(String? correlationId) Future
Closes component and frees used resources.
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
createQueue(String name) Future<void>
Creates a message queue. If connection doesn't support this function it exists without error.
deleteQueue(String name) Future<void>
Deletes a message queue. If connection doesn't support this function it exists without error.
getConnection() MqttServerClient?
isOpen() bool
Checks if the component is opened.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
open(String? correlationId) Future
Opens the component.
publish(String topic, String data, Map<String, dynamic> options) Future
Publish a message to a specified topic
readQueueNames() Future<List<String>>
Reads a list of registered queue names. If connection doesn't support this function returnes an empty list.
setReferences(IReferences references) → void
Sets references to dependent components.
subscribe(String topic, Map<String, dynamic> options, IMqttMessageListener listener) Future
toString() String
A string representation of this object.
unsubscribe(String topic, IMqttMessageListener listener) Future


operator ==(Object other) bool
The equality operator.