pip_services3_mqtt.connect.MqttConnection module

class pip_services3_mqtt.connect.MqttConnection.MqttConnection

Bases: pip_services3_messaging.connect.IMessageQueueConnection.IMessageQueueConnection, pip_services3_commons.refer.IReferenceable.IReferenceable, pip_services3_commons.config.IConfigurable.IConfigurable, pip_services3_commons.run.IOpenable.IOpenable

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)

### References ###

  • *:logger:*:*:1.0 (optional) ICounters 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, MessagingCapabilities

close(correlation_id: Optional[str])

Closes component and frees used resources.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

create_queue(name: str)

Creates a message queue. If connection doesn’t support this function it exists without error.

  • Note: Not supported

Parameters

name – the name of the queue to be created.

delete_queue(name: str)

Deletes a message queue. If connection doesn’t support this function it exists without error.

  • Note: Not supported

Parameters

name – the name of the queue to be deleted.

get_connection() → Any
is_open() → bool

Checks if the component is opened.

Returns

true if the component has been opened and false otherwise.

open(correlation_id: Optional[str])

Opens the component.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

publish(topic: str, data: Any, options: dict)

Publish a message to a specified topic

Parameters
  • topic – a topic name

  • data – a message to be published

  • options – publishing options

read_queue_names() → List[str]

Reads a list of registered queue names. If connection doesn’t support this function returnes an empty list.

  • Note: Not supported

Returns

a list with registered queue names.

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to dependent components.

Parameters

references – references to locate the component dependencies.

subscribe(topic: str, options: dict, listener: pip_services3_mqtt.connect.IMqttMessageListener.IMqttMessageListener)

Subscribe to a topic

Parameters
  • topic – a topic name

  • options – subscription options

  • listener – a message listener

unsubscribe(topic: str, listener: pip_services3_mqtt.connect.IMqttMessageListener.IMqttMessageListener)

Unsubscribe from a previously subscribed topic

Parameters
  • topic – a topic name

  • listener – a message listener