前言
本文的原文连接是: https://blog.csdn.net/freewebsys/article/details/87606981
未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys
1,关于mqtt-spy
项目地址:
https://github.com/eclipse/paho.mqtt-spy
和 mqttbox 两个客户端一个订阅一个发布:
https://github.com/eclipse/paho.mqtt-spy/releases
下载最新的 release 1.0.0 版本。
启动gui工具
java -jar mqtt-spy-0.3.0-jar-with-dependencies.jar
高级用法:
https://www.hivemq.com/blog/mqtt-toolbox-mqtt-spy-advanced/
2, 命令行模式 mqtt-spy-daemon
使用命令行进行连接 配置文件:
java -jar mqtt-spy-daemon-1.0.0.jar "./mqtt-spy-daemon-configuration.xml"
//当前文件夹目录
mqtt-spy-daemon-configuration.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mqttspydc:MqttSpyDaemonConfiguration xmlns:mqttspydc="http://baczkowicz.pl/mqtt-spy/daemon/configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Connection>
<!-- Port number is optional (default is 1883) -->
<ServerURI>127.0.0.1:1883</ServerURI>
<!-- Leave empty to auto-generate -->
<ClientID>test123456789</ClientID>
<MessageLog>DISABLED</MessageLog>
<!-- Receive messages publish by the sample_publish script -->
<Subscription topic="mqtt-spy-daemon/#" />
<!-- Publishing sample messages -->
<BackgroundScript>
<File>./sample-publish.js</File>
</BackgroundScript>
<!-- Exit the daemon when the script has finished -->
<RunningMode>SCRIPTS_ONLY</RunningMode>
</Connection>
</mqttspydc:MqttSpyDaemonConfiguration>
参数配置:
https://github.com/kamilfb/mqtt-spy/wiki/DaemonConfiguration
其中 file 一定要写上当前目录 ./sample-publish.js 否则会使用默认脚本。
sample-publish.js:
// Wrap the script in a method, so that you can do "return false;" in case of an error or stop request
function publish()
{
mqttspy.publish("mqtt-spy-daemon/test1", "hello");
mqttspy.publish("mqtt-spy-daemon/test2", "from");
mqttspy.publish("mqtt-spy-daemon/test3", "mqtt-spy-daemon!");
mqttspy.publish("mqtt-spy-daemon/test4", "mqtt-spy-daemon!");
for(var i = 0; i < 100; i ++){//循环 100 次。
logger.info("loop in "+i);// 打印日志
mqttspy.publish("mqtt-spy-daemon/test1", "hello"+i);
}
logger.info("Reading XML from a file...");
// This means all OK, script has completed without any issues and as expected
return true;
}
publish();
可以进行编写脚本:
https://github.com/eclipse/paho.mqtt-spy/wiki/Scripting
https://github.com/kamilfb/mqtt-spy/wiki/ScriptingPublications
https://github.com/eclipse/paho.mqtt-spy/issues/51
3,总结
mqtt-spy 是个java的客户端,可以gui使用,也可以使用命令行模式。
命令行模式支持使用 JavaScript 编写测试脚本。这样可以方便的进行测试梳理。
比写 jmeter 要方便点。编写代码比 java 简单点。
本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/87606981
博主地址是:http://blog.csdn.net/freewebsys