MqttBroker

Description

The MqttBroker object creates an MQTT broker listening for connections. An MQTT broker manages the exchange of subscribed and published topics for all connected clients.

› Inherits:

Object

Overview

Properties

Methods

Signals

Properties

enabled

This property holds whether the broker is enabled. If set to false the broker process is stopped.

› Type:

Boolean

› Default:

true

› Signal:

enabledChanged()

› Attributes:

Writable

internal

This property holds whether the broker should listen for incoming connections on the local loopback interface only. If set to true the broker will not be reachable by other hosts on the network but internal clients such as docker containers (DockerContainer) only.

› Type:

Boolean

› Default:

true

› Signal:

internalChanged()

› Attributes:

Writable

listeners

This property holds a list of MqttListener objects which define the actual connectivity options of the broker.

This property was introduced in InCore 2.6.

› Type:

List<MqttListener>

› Signal:

listenersChanged()

› Attributes:

Readonly

maxConnections

This property holds the maximum number of connections which the broker is allowed to manage concurrently.

› Type:

SignedInteger

› Default:

-1

› Signal:

maxConnectionsChanged()

› Attributes:

Writable, Optional

Signals

listenersDataChanged(SignedInteger index)

This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index in the listeners list itself emitted the dataChanged() signal.

Example

import InCore.Foundation 2.6
import InCore.Mqtt 2.6

Application {

    name: "MqttBrokerExample"

    Settings {
        id: settings
        property bool brokerEnabled : true;
    }

    // start an MQTT broker if enabled via settings
    MqttBroker {
        enabled: settings.brokerEnabled
        listeners: [
            MqttListener {
                internal: false
                port: 1883
            },
            MqttListener {
                internal: false
                port: 1884
                protocol: MqttListener.Websockets
            }
        ]
    }
}