跳转到主要内容

用于在多个主题上生成MQTT消息的工具

项目描述

在测试处理MQTT消息的应用程序和工具时,通常需要在随机主题上持续向代理发送消息。《mqtt-randompub》包含发送单个消息、指定数量的消息或直到工具终止的恒定流消息的选项。配置文件可用于存储主题列表以创建可重复的测试场景。

先决条件/安装

获取文件

克隆mqtt-randompub 仓库

git clone git@github.com:fabaff/mqtt-randompub.git

或使用pip进行安装。

pip3 install mqtt-randompub --user

依赖关系

mqtt-randompub 仅依赖于 paho-mqtt。此模块应在使用pip安装时自动引入。

Fedora系统

sudo dnf -y install python-paho-mqtt

用法

要在终端中运行mqtt-randompub,只需键入

$ mqtt-randompub -h
usage: mqtt-randompub [-h] [-c CONFIG] [-b BROKER] [-p PORT] [-q QOS]
                      [-t TOPIC] [-s SUBTOPIC1] [-d SUBTOPIC2] [-l LOAD]
                      [-i INTERVAL] [-n NUMBER]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        configuration file to use
  -b BROKER, --broker BROKER
                        set the broker
  -p PORT, --port PORT  set the proker port
  -q QOS, --qos QOS     set the QoS of the messages
  -t TOPIC, --topic TOPIC
                        set the main topic
  -s SUBTOPIC1, --subtopic1 SUBTOPIC1
                        set the first subtopic
  -d SUBTOPIC2, --subtopic2 SUBTOPIC2
                        set the second subtopic
  -l LOAD, --load LOAD  what to use as message payload
  -i INTERVAL, --interval INTERVAL
                        time in seconds between the messages
  -n NUMBER, --number NUMBER
                        number of messages to send. set to 0 for running

以查看所有选项。在没有选项的情况下运行将向监听在本地主机上的端口1883的代理发送示例消息到test/#

对于本地测试,请在 localhost 上运行一个 MQTT 代理/服务器。

  • mosca - 一个针对 node.js 的多传输 MQTT 代理(已不再维护)

  • mosquitto - 一个开源的 MQTT v3.1 代理

然后使用 MQTT 客户端订阅 test/# 主题。例如

mosquitto_sub -h localhost -d -t test/#

您可以使用配置文件运行 mqtt-randompub 以重用之前设置的主题。有关详细信息,请参阅 mqtt-randompub.example 文件。

许可证

mqtt-randompub 使用 MIT 许可,有关更多信息请查看 LICENSE。

项目详情


下载文件

下载适合您平台的应用文件。如果您不确定该选择哪个,请了解更多关于 安装包 的信息。

源代码分发

mqtt-randompub-0.2.2.tar.gz (6.1 kB 查看哈希值)

上传时间 源代码

构建分发

mqtt_randompub-0.2.2-py3-none-any.whl (6.7 kB 查看哈希值)

上传时间 Python 3

支持者