提交 b7086017 编写于 作者: 浅梦2013's avatar 浅梦2013

mqtt 3.1 协议会校验 clientId 长度,添加设置。

上级 81a5a5cc
......@@ -40,7 +40,7 @@ public class MqttServerAioHandler implements ServerAioHandler {
private final MqttServerProcessor processor;
public MqttServerAioHandler(MqttServerCreator serverCreator, MqttServerProcessor processor) {
this.mqttDecoder = new MqttDecoder(serverCreator.getMaxBytesInMessage());
this.mqttDecoder = new MqttDecoder(serverCreator.getMaxBytesInMessage(), serverCreator.getMaxClientIdLength());
this.mqttEncoder = MqttEncoder.INSTANCE;
this.allocator = serverCreator.getBufferAllocator();
this.processor = processor;
......
......@@ -114,6 +114,10 @@ public class MqttServerCreator {
* debug
*/
private boolean debug = false;
/**
* mqtt 3.1 会校验此参数
*/
private int maxClientIdLength = MqttConstant.DEFAULT_MAX_CLIENT_ID_LENGTH;
public String getName() {
return name;
......@@ -275,6 +279,15 @@ public class MqttServerCreator {
return this;
}
public int getMaxClientIdLength() {
return maxClientIdLength;
}
public MqttServerCreator maxClientIdLength(int maxClientIdLength) {
this.maxClientIdLength = maxClientIdLength;
return this;
}
public MqttServer start() {
Objects.requireNonNull(this.messageListener, "Mqtt Server message listener cannot be null.");
if (this.authHandler == null) {
......
......@@ -42,6 +42,10 @@ public class MqttServerTest {
.port(1883)
// 默认为: 8092(mqtt 默认最大消息大小),为了降低内存可以减小小此参数,如果消息过大 t-io 会尝试解析多次(建议根据实际业务情况而定)
.readBufferSize(512)
// 最大包体长度
// .maxBytesInMessage(1024 * 100)
// mqtt 3.1 协议会校验 clientId 长度。
// .maxClientIdLength(64)
.messageListener((clientId, topic, mqttQoS, payload) -> {
logger.info("clientId:{} topic:{} mqttQoS:{} message:{}", clientId, topic, mqttQoS, ByteBufferUtil.toString(payload));
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册