Skip to content
Permalink
Browse files

增加mqtt客户端模拟器

  • Loading branch information...
zhou-hao committed Aug 23, 2018
1 parent 16e60e5 commit f56d52b9298ed90d22bf229ad0e0a807f42305a3
@@ -23,3 +23,4 @@ pom.xml.versionsBackup
build/
/data/
!/.mvn/wrapper/maven-wrapper.jar
bin/
@@ -31,6 +31,7 @@
------------------iot-logging # 访问日志,系统日志集成
------------------iot-redis # redis集成
------------------server-dependencies # 微服务通用依赖
-------------mqtt-emulator # mqtt客户端模拟器
-------------user-server # 用户服务
-------------interaction-server # 物联网设备交互服务

@@ -0,0 +1,2 @@
./kafka-console-consumer.sh --topic iot.device.report.temp-test \
--bootstrap-server localhost:9092
@@ -20,5 +20,5 @@ logging:
level:
org.hswebframework.web: DEBUG
org.hswebframework.web.cache: WARN
org.hswebframework.iot: DEBUG
# org.hswebframework.iot: warn
org.apache.kafka.clients: warn
@@ -21,6 +21,19 @@
<version>1.0.26</version>
</dependency>

<!--swagger-->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>spring-boot-starter-swagger</artifactId>
<!--<scope>provided</scope>-->
</dependency>

<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<!--<scope>provided</scope>-->
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
@@ -0,0 +1,77 @@
# MQTT客户端模拟器

用户模拟多个mqtt客户端,以及指令接收,反馈,数据上报等功能.

# 准备数据

程序运行需要数据文件:

1. data/clients.txt ,要连接的客户端列表,一个客户端一行,格式: clientId:password
2. data/reply.json , 客户端收到服务器指令是做出回复的数据.
```json
{
//(对应服务端指令中的operation)
"PLUGIN_INSTALL":
[ //如果集合中存在多条数据,随机一条进行回复
{
//(延迟回复,随机0到10000毫秒)
"delay": [
0,
10000
],
//自定义回复格式
"operation": "plugin",
"code": 0
}
]
}
```
3. data/report.json ,客户端定时上报的数据

随机抽取集合中的数据进行上报
```json
[
{
"action": "temp-test",
"data": {
"key": 1,
"key2": "2"
}
},
{
"action": "temp-test",
"data": {
"key": 10000,
"key2": "value"
}
}
]
```

# 打包,运行
```bash
$ ./build.sh
构建成功
$ cd bin
$ java -jar mqtt-emulator.jar servers=tcp://127.0.0.1:1883
```

# docker
```bash
$ docker run -it --rm hsweb/iot-cloud-mqtt-benchmark servers=tcp://mqtt-host:1883
```

使用自定义数据
```bash
$ docker run -v my-data-dir:/app/data -it --rm hsweb/iot-cloud-mqtt-benchmark servers=tcp://mqtt-host:1883
```

# 参数

servers=tcp://host:port # mqtt的服务器地址
clients=./data/clients.txt # 需要连接的客户端列表文件
autoReconnect=*true/false # 是否自动重连
skip=0 # 从clients.txt的第几行开始
limit=2147483647 # 最大客户端数量
disableReport=true/*false # 是否定时上报数据,上报数据的文件为./data/report.json中的随机内容
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
if [ ! -d "bin" ]; then
mkdir -p bin/
fi
cp -r data bin/
cp -r help.txt bin/
touch install.log
mvn clean compile -Dmaven.test.skip > install.log
install_result=$(cat install.log | tail -10)
if [[ $install_result =~ "BUILD SUCCESS" ]];then
mvn assembly:assembly -Dmaven.test.skip > install.log
install_result=$(cat install.log | tail -10)
if [[ $install_result =~ "BUILD SUCCESS" ]];then
cp target/mqtt-emulator-jar-with-dependencies.jar bin/mqtt-emulator.jar
echo "构建成功"
else
cat install.log
fi
else
cat install.log
fi
@@ -0,0 +1,115 @@
1032209087655605288:1032209087655605294
1032209087655605297:1032209087655605303
1032209087655605306:1032209087655605312
1032209087655605315:1032209087655605321
1032209087655605324:1032209087655605330
1032209087655605333:1032209087655605339
1032209087655605342:1032209087655605348
1032209087659798530:1032209087659798536
1032209087659798539:1032209087659798545
1032209087659798548:1032209087659798554
1032209087659798557:1032209087659798563
1032209087659798566:1032209087659798572
1032209087659798575:1032209087659798581
1032209087659798584:1032209087659798590
1032209087659798593:1032209087659798599
1032209087659798602:1032209087659798608
1032209087659798611:1032209087659798617
1032209087659798620:1032209087659798626
1032209087659798629:1032209087659798635
1032209087659798638:1032209087659798644
1032209087659798647:1032209087659798653
1032209087659798656:1032209087659798662
1032209087659798665:1032209087659798671
1032209087659798674:1032209087659798680
1032209087659798683:1032209087659798689
1032209087659798692:1032209087659798698
1032209087659798701:1032209087659798707
1032209087659798710:1032209087659798716
1032209087659798719:1032209087659798725
1032209087659798728:1032209087659798734
1032209087659798737:1032209087659798743
1032209087659798746:1032209087659798752
1032209087659798755:1032209087659798761
1032209087659798764:1032209087659798770
1032209087659798773:1032209087659798779
1032209087659798782:1032209087659798788
1032209087659798791:1032209087659798797
1032209087659798800:1032209087659798806
1032209087659798809:1032209087659798815
1032209087659798818:1032209087659798824
1032209087659798827:1032209087659798833
1032209087659798836:1032209087659798842
1032209087659798845:1032209087659798851
1032209087659798854:1032209087659798860
1032209087659798863:1032209087659798869
1032209087659798872:1032209087659798878
1032209087659798881:1032209087659798887
1032209087659798890:1032209087659798896
1032209087659798899:1032209087659798905
1032209087659798908:1032209087659798914
1032209087659798917:1032209087659798923
1032209087659798926:1032209087659798932
1032209087659798935:1032209087659798941
1032209087659798944:1032209087659798950
1032209087659798953:1032209087659798959
1032209087659798962:1032209087659798968
1032209087659798971:1032209087659798977
1032209087659798980:1032209087659798986
1032209087659798989:1032209087659798995
1032209087659798998:1032209087659799004
1032209087659799007:1032209087659799013
1032209087659799016:1032209087659799022
1032209087659799025:1032209087659799031
1032209087659799034:1032209087659799040
1032209087659799043:1032209087659799049
1032209087659799052:1032209087659799058
1032209087659799061:1032209087659799067
1032209087659799070:1032209087659799076
1032209087659799079:1032209087659799085
1032209087659799088:1032209087659799094
1032209087659799097:1032209087659799103
1032209087659799106:1032209087659799112
1032209087659799115:1032209087659799121
1032209087659799124:1032209087659799130
1032209087659799133:1032209087659799139
1032209087659799142:1032209087659799148
1032209087659799151:1032209087659799157
1032209087659799160:1032209087659799166
1032209087659799169:1032209087659799175
1032209087659799178:1032209087659799184
1032209087659799187:1032209087659799193
1032209087659799196:1032209087659799202
1032209087659799205:1032209087659799211
1032209087659799214:1032209087659799220
1032209087659799223:1032209087659799229
1032209087659799232:1032209087659799238
1032209087659799241:1032209087659799247
1032209087659799250:1032209087659799256
1032209087659799259:1032209087659799265
1032209087659799268:1032209087659799274
1032209087659799277:1032209087659799283
1032209087659799286:1032209087659799292
1032209087659799295:1032209087659799301
1032209087659799304:1032209087659799310
1032209087659799313:1032209087659799319
1032209087659799322:1032209087659799328
1032209087659799331:1032209087659799337
1032209087659799340:1032209087659799346
1032209087659799349:1032209087659799355
1032209087659799358:1032209087659799364
1032209087659799367:1032209087659799373
1032209087659799376:1032209087659799382
1032209087659799385:1032209087659799391
1032209087659799394:1032209087659799400
1032209087659799403:1032209087659799409
1032209087659799412:1032209087659799418
1032209087659799421:1032209087659799427
1032209087659799430:1032209087659799436
1032209087659799439:1032209087659799445
1032209087659799448:1032209087659799454
1032209087659799457:1032209087659799463
1032209087659799466:1032209087659799472
1032209087659799475:1032209087659799481
1032209087663992834:1032209087663992840
1032209087663992843:1032209087663992849
@@ -0,0 +1,46 @@
{
"PLUGIN_INSTALL": [
{
"operation": "plugin",
"delay": [
0,
10000
],
"code": 0
}
],
"PLUGIN_START": [
{
"operation": "plugin",
"delay": [
0,
10000
],
"code": 0
},
{
"operation": "plugin",
"code": 1
}
],
"PLUGIN_STOP": [
{
"operation": "plugin",
"delay": [
0,
10000
],
"code": 0
}
],
"PLUGIN_UNINSTALL": [
{
"operation": "plugin",
"delay": [
0,
10000
],
"code": 0
}
]
}
@@ -0,0 +1,16 @@
[
{
"action": "temp-test",
"data": {
"key": 1,
"key2": "2"
}
},
{
"action": "temp-test",
"data": {
"key": 10000,
"key2": "value"
}
}
]
@@ -0,0 +1,10 @@
参数:
servers=tcp://host:port # mqtt的服务器地址
clients=./data/clients.txt # 需要连接的客户端列表文件
autoReconnect=*true/false # 是否自动重连
skip=0 # 从clients.txt的第几行开始
limit=2147483647 # 最大客户端数量
disableReport=true/*false # 是否定时上报数据,上报数据的文件为./data/report.json中的随机内容

例如:
java -jar mqtt-benchmark.run.jar disableReport=true servers=tcp://mqtt-server:1883
Oops, something went wrong.

0 comments on commit f56d52b

Please sign in to comment.
You can’t perform that action at this time.