The :class:`~hbmqtt.broker.Broker` class provides a complete MQTT 3.1.1 broker implementation. This class allows Python developers to embed a MQTT broker in their own applications.
Usage example
-------------
The following example shows how to start a broker using the default configuration:
When executed, this script gets the default event loop and asks it to run the ``broker_coro`` until it completes.
``broker_coro`` creates :class:`~hbmqtt.broker.Broker` instance and then :meth:`~hbmqtt.broker.Broker.start` the broker for serving.
Once completed, the loop is ran forever, making this script never stop ...
Reference
---------
Broker API
..........
..automodule:: hbmqtt.broker
..autoclass:: Broker
..automethod:: start
..automethod:: shutdown
Broker configuration
....................
The :class:`~hbmqtt.broker.Broker```__init__`` method accepts a ``config`` parameter which allow to setup some behaviour and defaults settings. This argument must be a Python dict object. For convinience, it is presented below as a YAML file [1]_.
The ``listeners`` section allows to define network listeners which must be started by the :class:`~hbmqtt.broker.Broker`. Several listeners can be setup. ``default`` subsection defines common attributes for all listeners. Each listener can have the following settings:
*``bind``: IP address and port binding.
*``max-connections``: Set maximum number of active connection for the listener. ``0`` means no limit.
*``type``: transport protocol type; can be ``tcp`` for classic TCP listener or ``ws`` for MQTT over websocket.
*``ssl`` enables (``on``) or disable secured connection over the transport protocol.
*``cafile``, ``cadata``, ``certfile`` and ``keyfile`` : mandatory parameters for SSL secured connections.
The ``auth`` section setup authentication behaviour:
*``plugins``: defines the list of activated plugins. Note the plugins must be defined in the ``hbmqtt.broker.plugins```entry point <https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins>`_.
*``allow-anonymous`` : used by the internal :class:`hbmqtt.plugins.authentication.AnonymousAuthPlugin` plugin. This parameter enables (``on``) or disable anonymous connection, ie. connection without username.
*``password-file`` : used by the internal :class:`hbmqtt.plugins.authentication.FileAuthPlugin` plugin. This parameter gives to path of the password file to load for authenticating users.
The ``topic-check`` section setup access control policies for publishing and subscribing to topics:
*``enabled``: set to true if you want to impose an access control policy. Otherwise, set it to false.
*``plugins``: defines the list of activated plugins. Note the plugins must be defined in the ``hbmqtt.broker.plugins```entry point <https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins>`_.