Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MqttConnection

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) 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]]

Hierarchy

  • MqttConnection

Implements

  • any
  • any
  • any
  • any

Index

Constructors

constructor

  • Creates a new instance of the connection component.

    Returns MqttConnection

Properties

Protected _clientId

_clientId: string = os.hostname()

Protected _connectTimeout

_connectTimeout: number = 30000

Protected _connection

_connection: any

The NATS connection pool object.

Protected _connectionResolver

_connectionResolver: MqttConnectionResolver = new MqttConnectionResolver()

The connection resolver.

Protected _keepAliveTimeout

_keepAliveTimeout: number = 60000

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

The logger.

Protected _options

_options: ConfigParams = new ConfigParams()

The configuration options.

Protected _reconnectTimeout

_reconnectTimeout: number = 1000

Protected _retryConnect

_retryConnect: boolean = true

Protected _subscriptions

_subscriptions: MqttSubscription[] = []

Topic subscriptions

Methods

Protected checkOpen

  • checkOpen(): any
  • Checks if connection is open

    Returns any

    an error is connection is closed or null otherwise.

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

createQueue

  • createQueue(name: string, callback: function): void
  • Creates a message queue. If connection doesn't support this function it exists without error.

    Parameters

    • name: string

      the name of the queue to be created.

    • callback: function

      notifies about completion with error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

deleteQueue

  • deleteQueue(name: string, callback: function): void
  • Deletes a message queue. If connection doesn't support this function it exists without error.

    Parameters

    • name: string

      the name of the queue to be deleted.

    • callback: function

      notifies about completion with error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

getConnection

  • getConnection(): any
  • Returns any

isOpen

  • isOpen(): boolean
  • Checks if the component is opened.

    Returns boolean

    true if the component has been opened and false otherwise.

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

publish

  • publish(topic: string, data: Buffer, options: any, callback?: function): void
  • Publish a message to a specified topic

    Parameters

    • topic: string

      a topic name

    • data: Buffer

      a message to be published

    • options: any

      publishing options

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

readQueueNames

  • readQueueNames(callback: function): void
  • Reads a list of registered queue names. If connection doesn't support this function returnes an empty list.

    callback

    to receive a list with registered queue names or an error.

    Parameters

    • callback: function
        • (err: any, queueNames: string[]): void
        • Parameters

          • err: any
          • queueNames: string[]

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

subscribe

  • Subscribe to a topic

    Parameters

    • topic: string

      a topic name

    • options: any

      subscription options

    • listener: IMqttMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

unsubscribe

  • Unsubscribe from a previously subscribed topic

    Parameters

    • topic: string

      a topic name

    • listener: IMqttMessageListener

      a message listener

    • Optional callback: function

      (optional) callback to receive notification on operation result

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc