Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica-mqtt
提交
7c5f9b5c
mica-mqtt
项目概览
mica
/
mica-mqtt
通知
71
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica-mqtt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7c5f9b5c
编写于
9月 16, 2020
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
使用 Tio.close 进行关闭。
上级
3f2bd444
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
181 addition
and
5 deletion
+181
-5
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/client/MqttClientConfig.java
...va/net/dreamlu/iot/mqtt/core/client/MqttClientConfig.java
+57
-0
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/client/MqttWillMessage.java
...ava/net/dreamlu/iot/mqtt/core/client/MqttWillMessage.java
+121
-0
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/MqttServerAioHandler.java
...et/dreamlu/iot/mqtt/core/server/MqttServerAioHandler.java
+2
-4
mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/server/MqttBrokerProcessorImpl.java
.../net/dreamlu/iot/mqtt/server/MqttBrokerProcessorImpl.java
+1
-1
未找到文件。
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/client/MqttClientConfig.java
0 → 100644
浏览文件 @
7c5f9b5c
package
net.dreamlu.iot.mqtt.core.client
;
import
net.dreamlu.iot.mqtt.codec.MqttVersion
;
/**
* MqttClient 配置
*
* @author L.cm
*/
public
class
MqttClientConfig
{
/**
* ip,可为空,为空 t-io 默认为 127.0.0.1
*/
private
String
ip
;
/**
* 端口
*/
private
int
port
;
/**
* 超时时间,t-io 配置,可为 null
*/
private
Integer
timeout
;
/**
* 自动重连
*/
private
boolean
reconnect
=
true
;
/**
* 重连重试时间
*/
private
Long
reInterval
;
/**
* 客户端 id,默认:随机生成
*/
private
String
clientId
;
/**
* mqtt 协议,默认:3_1_1
*/
private
MqttVersion
protocolVersion
=
MqttVersion
.
MQTT_3_1_1
;
/**
* 用户名
*/
private
String
username
=
null
;
/**
* 密码
*/
private
String
password
=
null
;
/**
* 清除会话
*/
private
boolean
cleanSession
=
true
;
/**
* 遗嘱消息
*/
private
MqttWillMessage
willMessage
;
}
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/client/MqttWillMessage.java
0 → 100644
浏览文件 @
7c5f9b5c
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.net.dreamlu.net).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
net.dreamlu.iot.mqtt.core.client
;
import
net.dreamlu.iot.mqtt.codec.MqttQoS
;
import
java.util.Objects
;
/**
* 遗嘱消息
*
* @author L.cm
*/
public
final
class
MqttWillMessage
{
private
final
String
topic
;
private
final
String
message
;
private
final
boolean
retain
;
private
final
MqttQoS
qos
;
private
MqttWillMessage
(
String
topic
,
String
message
,
boolean
retain
,
MqttQoS
qos
)
{
this
.
topic
=
topic
;
this
.
message
=
message
;
this
.
retain
=
retain
;
this
.
qos
=
qos
;
}
public
String
getTopic
()
{
return
topic
;
}
public
String
getMessage
()
{
return
message
;
}
public
boolean
isRetain
()
{
return
retain
;
}
public
MqttQoS
getQos
()
{
return
qos
;
}
public
static
MqttWillMessage
.
Builder
builder
()
{
return
new
MqttWillMessage
.
Builder
();
}
public
static
final
class
Builder
{
private
String
topic
;
private
String
message
;
private
boolean
retain
;
private
MqttQoS
qos
;
public
Builder
topic
(
String
topic
)
{
this
.
topic
=
Objects
.
requireNonNull
(
topic
);
return
this
;
}
public
Builder
message
(
String
message
)
{
this
.
message
=
Objects
.
requireNonNull
(
message
);
return
this
;
}
public
Builder
retain
(
boolean
retain
)
{
this
.
retain
=
retain
;
return
this
;
}
public
Builder
qos
(
MqttQoS
qos
)
{
this
.
qos
=
Objects
.
requireNonNull
(
qos
);
return
this
;
}
public
MqttWillMessage
build
()
{
return
new
MqttWillMessage
(
topic
,
message
,
retain
,
qos
);
}
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
MqttWillMessage
that
=
(
MqttWillMessage
)
o
;
return
retain
==
that
.
retain
&&
Objects
.
equals
(
topic
,
that
.
topic
)
&&
Objects
.
equals
(
message
,
that
.
message
)
&&
qos
==
that
.
qos
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
topic
,
message
,
retain
,
qos
);
}
@Override
public
String
toString
()
{
return
"MqttWillMessage{"
+
"topic='"
+
topic
+
'\''
+
", message='"
+
message
+
'\''
+
", retain="
+
retain
+
", qos="
+
qos
+
'}'
;
}
}
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/MqttServerAioHandler.java
浏览文件 @
7c5f9b5c
...
...
@@ -148,23 +148,21 @@ public class MqttServerAioHandler implements ServerAioHandler {
private
void
processFailure
(
ChannelContext
context
,
MqttMessage
mqttMessage
)
{
Throwable
cause
=
mqttMessage
.
decoderResult
().
getCause
();
if
(
cause
instanceof
MqttUnacceptableProtocolVersionException
)
{
log
.
error
(
cause
.
getMessage
());
// 不支持的协议版本
MqttConnAckMessage
message
=
MqttMessageBuilders
.
connAck
()
.
returnCode
(
MqttConnectReturnCode
.
CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION
)
.
sessionPresent
(
false
)
.
build
();
Tio
.
send
(
context
,
message
);
context
.
setClosed
(
true
);
Tio
.
close
(
context
,
cause
,
"MqttUnacceptableProtocolVersion"
);
}
else
if
(
cause
instanceof
MqttIdentifierRejectedException
)
{
log
.
error
(
cause
.
getMessage
());
// 不合格的 clientId
MqttConnAckMessage
message
=
MqttMessageBuilders
.
connAck
()
.
returnCode
(
MqttConnectReturnCode
.
CONNECTION_REFUSED_IDENTIFIER_REJECTED
)
.
sessionPresent
(
false
)
.
build
();
Tio
.
send
(
context
,
message
);
context
.
setClosed
(
true
);
Tio
.
close
(
context
,
cause
,
"MqttIdentifierRejected"
);
}
else
if
(
cause
instanceof
DecoderException
)
{
log
.
error
(
cause
.
getMessage
(),
cause
);
// 消息解码异常,怎么处理?只打印异常?
...
...
mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/server/MqttBrokerProcessorImpl.java
浏览文件 @
7c5f9b5c
...
...
@@ -140,7 +140,7 @@ public class MqttBrokerProcessorImpl implements MqttServerProcessor {
public
void
processDisConnect
(
ChannelContext
context
)
{
String
clientId
=
context
.
getBsId
();
log
.
debug
(
"DISCONNECT - clientId: {}"
,
clientId
);
context
.
setClosed
(
true
);
Tio
.
close
(
context
,
"MqttIdentifierRejected"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录