Skip to content

MQTT

MQTT (Message Queuing Telemetry Transport) is an open-source messaging protocol known for its efficiency and low latency. It uses a publish/subscribe model, making it a scalable and cost-effective solution for connecting devices. An MQTT communication system includes a publishing server, a broker, and multiple clients. This protocol is ideal for devices with limited resources and networks with low bandwidth, high latency, or instability.

Installation

Bash
pip install aiomqtt

Overview

To use the Mqtt transporter, pass the following options object to the create_microservice() method:

Python
from app_module import AppModule

from nestipy.core import NestipyFactory
from nestipy.microservice import MicroserviceOption, Transport, MicroserviceClientOption

app = NestipyFactory.create_microservice(
    AppModule, [
        MicroserviceOption(
            transport=Transport.MQTT,
            option=MicroserviceClientOption(
                host="localhost",
                port=1883
            )
        )
    ]
)

Client

Python
from nestipy.common import Module
from nestipy.microservice import ClientsModule, ClientsConfig, MicroserviceClientOption, MicroserviceOption, Transport


@Module(
    imports=[
        ClientsModule.register([
            ClientsConfig(
                name="MATH_SERVICE",
                option=MicroserviceOption(
                    transport=Transport.MQTT,
                    option=MicroserviceClientOption(
                        host="localhost",
                        port=1883
                    )
                )
            )
        ]),
    ]
    ...
)
class AppModule:
    ...

Support us

Nestipy is a project released under the MIT license, meaning it's open source and freely available for use and modification. Its development thrives with the generous contributions of these fantastic individuals.