Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mqtt模拟器):新增断开重试参数 #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions benchmark/mqtt/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* JetLinks mqtt 官方协议模拟器
* benchmark mqtt --host=127.0.0.1 --port=8801 --script=demo/tcp/benchmark.js report=true reportLimit=100 interval=1000
* --reconnectAttempts=3 重试次数
* --reconnectInterval=1000 重试间隔
*/

//绑定内置参数,否则匿名函数无法使用。
Expand Down Expand Up @@ -67,11 +69,11 @@ function reportProperties(client) {
"containsGeo": false,
"ignoreLog": true,
"ignoreStorage": true
}
}
}

//推送mqtt
return client.publishAsync("/report-property", 0, $benchmark.toJson(msg));
return client.publishAsync(createTopic(client, "/properties/report"), 0, $benchmark.toJson(msg));

}

Expand Down
3 changes: 2 additions & 1 deletion run-cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
mvn clean package -DskipTests \
&& clear \
&& java \
&&
java \
-Dfile.encoding=UTF-8 \
-Xmx1G \
-Dsimulator.max-ports=50000 \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetlinks.simulator.cmd.benchmark;

import lombok.extern.slf4j.Slf4j;
import org.jetlinks.simulator.cmd.NetClientCommandOption;
import org.jetlinks.simulator.cmd.NetworkInterfaceCompleter;
import org.jetlinks.simulator.core.Connection;
Expand All @@ -12,6 +13,7 @@
import java.net.InetSocketAddress;
import java.util.Collections;

@Slf4j
@CommandLine.Command(name = "mqtt",
showDefaultValues = true,
description = {
Expand All @@ -37,7 +39,11 @@ protected Mono<? extends Connection> createConnection(ConnectCreateContext ctx)
return MqttClient
.connect(
InetSocketAddress.createUnresolved(command.getHost(), command.getPort()),
commandOptions
commandOptions,
() -> {
log.info("断开重试触发beforeConnect开始:{},{}", commandOptions.getUsername());
ctx.beforeConnect(commandOptions);
}
);
}

Expand Down Expand Up @@ -79,6 +85,16 @@ public void setPassword0(String password) {
@CommandLine.Option(names = {"--topics"}, description = "attach and subscribe topics", order = 6)
private String[] topics;

@CommandLine.Option(names = {"--reconnectAttempts"}, description = "MQTT reconnect times", order = 7)
public void setReconnect(int attemps) {
super.setReconnectAttempts(attemps);
}

@CommandLine.Option(names = {"--reconnectInterval"}, description = "MQTT reconnect interval", order = 8)
public void setReconnectInterval0(long interval) {
super.setReconnectInterval(interval);
}


}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package org.jetlinks.simulator.cmd.mqtt;

import io.vertx.core.net.NetClientOptions;
import org.jetlinks.simulator.cmd.AbstractCommand;
import org.jetlinks.simulator.cmd.NetClientCommandOption;
import org.jetlinks.simulator.cmd.NetworkInterfaceCompleter;
import org.jetlinks.simulator.core.ExceptionUtils;
import org.jetlinks.simulator.core.network.mqtt.MqttClient;
import org.springframework.util.CollectionUtils;
import picocli.CommandLine;

import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.time.Duration;
import java.util.StringJoiner;

@CommandLine.Command(name = "connect",
showDefaultValues = true,
Expand Down Expand Up @@ -86,6 +81,17 @@ public void setPassword0(String password) {
@CommandLine.Option(names = {"--topics"}, description = "attach and subscribe topics", order = 6)
private String[] topics;

@CommandLine.Option(names = {"--reconnectAttempts"}, description = "MQTT reconnect times", order = 7)
public void setReconnect(int attemps) {
super.setReconnectAttempts(attemps);
}

@CommandLine.Option(names = {"--reconnectInterval"}, description = "MQTT reconnect interval", order = 8)
public void setReconnectInterval0(long interval) {
super.setReconnectInterval(interval);
}


}
}

2 changes: 1 addition & 1 deletion simulator-cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</encoder>
</appender>

<root level="WARN">
<root level="info">
<appender-ref ref="TERMINAL"/>
</root>
</configuration>
Loading