derberg / python-mqtt-client-template

This template generates MQTT Python client module. Its purpose is to abstract for the application client technical information about the broker and the names of topics it should use. Instead, it generates a module that provides a set of indent-driven functions that one can invoke to send a message to the application through the message broker.
2 stars 1 forks source link

Overview

This template generates MQTT Python client module. Its purpose is to abstract for the application client technical information about the broker and the names of topics it should use. Instead, it generates a module that provides a set of indent-driven functions that one can invoke to send or receive messages to the application through the message broker.

Technical requirements

1.10.0 =< Generator < 2.0.0

Specification requirements

The table contains information on parts of the specification required by this template to generate the proper output.

Property name Reason Fallback Default
channels.{channel}.{operation}.operationId To generate function names it is required to specify them in AsyncAPI document through operationId field. - -

Supported protocols

MQTT

How to use the template

Generate code:

asyncapi generate fromTemplate https://raw.githubusercontent.com/derberg/python-mqtt-client-template/main/test/fixtures/asyncapi.yml https://github.com/derberg/python-mqtt-client-template --output myclient --force-write --param server=dev

You can also clone this template locally and run npm test to check it in action based on examples. Just remember to use some client to verify if tests are really sending or receiving messages to the broker.

Subscribe to a broker to see if the test is sending messages properly:

docker run hivemq/mqtt-cli sub -t comment/liked -h test.mosquitto.org

Publish to a broker to see if the test is consuming messages properly:

docker run hivemq/mqtt-cli pub -t comment/views -h test.mosquitto.org -m receiving-messages

Template configuration

You can configure this template by passing different parameters in the AsyncAPI CLI: -p PARAM1_NAME=PARAM1_VALUE PARAM2_NAME=PARAM2_VALUE

Name Description Required Default Allowed Values Example
server The server you want to use in the code. Yes - - production

Development

The most straightforward command to generate code on local during development is:

asyncapi generate fromTemplate test/fixtures/asyncapi.yml ./ --output test/project --force-write --param server=dev

For local development, you need different variations of this command. First of all, you need to know about three important CLI flags: