Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica-mqtt
提交
6aadba08
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 搜索 >>
提交
6aadba08
编写于
9月 08, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
添加 mica-mqtt-broker,待完善。
上级
35be2f17
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
321 addition
and
27 deletion
+321
-27
README.md
README.md
+1
-0
mica-mqtt-broker/README.md
mica-mqtt-broker/README.md
+5
-0
mica-mqtt-broker/pom.xml
mica-mqtt-broker/pom.xml
+5
-0
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/MqttBrokerApplication.java
...va/net/dreamlu/iot/mqtt/broker/MqttBrokerApplication.java
+0
-4
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageDispatcher.java
...u/iot/mqtt/broker/cluster/RedisMqttMessageDispatcher.java
+56
-0
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageReceiver.java
...mlu/iot/mqtt/broker/cluster/RedisMqttMessageReceiver.java
+79
-0
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageStore.java
...reamlu/iot/mqtt/broker/cluster/RedisMqttMessageStore.java
+67
-0
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/config/MqttBrokerConfiguration.java
...eamlu/iot/mqtt/broker/config/MqttBrokerConfiguration.java
+22
-6
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/config/package-info.java
...java/net/dreamlu/iot/mqtt/broker/config/package-info.java
+0
-1
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/enums/RedisKeys.java
...ain/java/net/dreamlu/iot/mqtt/broker/enums/RedisKeys.java
+62
-0
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/listener/MqttBrokerConnectListener.java
...u/iot/mqtt/broker/listener/MqttBrokerConnectListener.java
+8
-2
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/listener/MqttBrokerMessageListener.java
...u/iot/mqtt/broker/listener/MqttBrokerMessageListener.java
+1
-1
mica-mqtt-broker/src/main/resources/application.yml
mica-mqtt-broker/src/main/resources/application.yml
+1
-0
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/model/Message.java
.../java/net/dreamlu/iot/mqtt/core/server/model/Message.java
+8
-8
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/store/IMqttMessageStore.java
...dreamlu/iot/mqtt/core/server/store/IMqttMessageStore.java
+2
-2
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/store/InMemoryMqttMessageStore.java
.../iot/mqtt/core/server/store/InMemoryMqttMessageStore.java
+3
-2
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/support/DefaultMqttServerProcessor.java
.../mqtt/core/server/support/DefaultMqttServerProcessor.java
+1
-1
未找到文件。
README.md
浏览文件 @
6aadba08
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
-
[x] 支持 GraalVM 编译成本机可执行程序。
-
[x] 支持 GraalVM 编译成本机可执行程序。
-
[x] 支持 Spring boot 项目快速接入(mica-mqtt-spring-boot-starter)。
-
[x] 支持 Spring boot 项目快速接入(mica-mqtt-spring-boot-starter)。
-
[x] mica-mqtt-spring-boot-starter 支持对接 Prometheus + Grafana。
-
[x] mica-mqtt-spring-boot-starter 支持对接 Prometheus + Grafana。
-
[
x] 基于 redis pub/sub 实现集群,详见 [mica-mqtt-broker 模块
](
mica-mqtt-broker
)
。
## 待办
## 待办
-
[ ] 优化处理 mqtt session,以及支持 v5.0
-
[ ] 优化处理 mqtt session,以及支持 v5.0
...
...
mica-mqtt-broker/README.md
0 → 100644
浏览文件 @
6aadba08
# mica-mqtt-broker 文档
## 功能
-
基于 redis pub/sub 实现集群。
-
redis 客户端状态存储。
mica-mqtt-broker/pom.xml
浏览文件 @
6aadba08
...
@@ -53,6 +53,11 @@
...
@@ -53,6 +53,11 @@
<groupId>
io.micrometer
</groupId>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-registry-prometheus
</artifactId>
<artifactId>
micrometer-registry-prometheus
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</dependencies>
<dependencyManagement>
<dependencyManagement>
...
...
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/MqttBrokerApplication.java
浏览文件 @
6aadba08
...
@@ -18,8 +18,6 @@ package net.dreamlu.iot.mqtt.broker;
...
@@ -18,8 +18,6 @@ package net.dreamlu.iot.mqtt.broker;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
/**
* mica mqtt broker
* mica mqtt broker
...
@@ -27,8 +25,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
...
@@ -27,8 +25,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @author L.cm
* @author L.cm
*/
*/
@SpringBootApplication
@SpringBootApplication
@EnableScheduling
@EnableCaching
public
class
MqttBrokerApplication
{
public
class
MqttBrokerApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageDispatcher.java
0 → 100644
浏览文件 @
6aadba08
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & 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.broker.cluster
;
import
net.dreamlu.iot.mqtt.core.server.dispatcher.IMqttMessageDispatcher
;
import
net.dreamlu.iot.mqtt.core.server.model.Message
;
import
net.dreamlu.mica.core.utils.JsonUtil
;
import
net.dreamlu.mica.redis.cache.MicaRedisCache
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
java.util.Objects
;
/**
* redis 消息转发器
*
* @author L.cm
*/
public
class
RedisMqttMessageDispatcher
implements
IMqttMessageDispatcher
{
private
final
RedisTemplate
<
String
,
Object
>
redisTemplate
;
private
final
byte
[]
channelBytes
;
public
RedisMqttMessageDispatcher
(
MicaRedisCache
redisCache
,
String
channel
)
{
this
.
redisTemplate
=
redisCache
.
getRedisTemplate
();
this
.
channelBytes
=
RedisSerializer
.
string
().
serialize
(
Objects
.
requireNonNull
(
channel
,
"Redis pub/sub channel is null."
));
}
@Override
public
boolean
send
(
Message
message
)
{
// 手动序列化和反序列化,避免 redis 序列化不一致问题
final
byte
[]
messageBytes
=
JsonUtil
.
toJsonAsBytes
(
message
);
redisTemplate
.
execute
((
RedisCallback
<
Long
>)
connection
->
connection
.
publish
(
channelBytes
,
messageBytes
));
return
true
;
}
@Override
public
boolean
send
(
String
clientId
,
Message
message
)
{
message
.
setClientId
(
clientId
);
return
send
(
message
);
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageReceiver.java
0 → 100644
浏览文件 @
6aadba08
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & 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.broker.cluster
;
import
net.dreamlu.iot.mqtt.codec.MqttQoS
;
import
net.dreamlu.iot.mqtt.core.server.MqttServer
;
import
net.dreamlu.iot.mqtt.core.server.model.Message
;
import
net.dreamlu.mica.core.utils.JsonUtil
;
import
net.dreamlu.mica.core.utils.StringUtil
;
import
net.dreamlu.mica.redis.cache.MicaRedisCache
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.data.redis.connection.MessageListener
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
java.nio.ByteBuffer
;
import
java.util.Objects
;
/**
* 监听集群消息
*
* @author L.cm
*/
public
class
RedisMqttMessageReceiver
implements
MessageListener
,
InitializingBean
{
private
final
RedisTemplate
<
String
,
Object
>
redisTemplate
;
private
final
String
channel
;
private
final
MqttServer
mqttServer
;
public
RedisMqttMessageReceiver
(
MicaRedisCache
redisCache
,
String
channel
,
MqttServer
mqttServer
)
{
this
.
redisTemplate
=
redisCache
.
getRedisTemplate
();
this
.
channel
=
Objects
.
requireNonNull
(
channel
,
"Redis pub/sub channel is null."
);
this
.
mqttServer
=
mqttServer
;
}
@Override
public
void
onMessage
(
org
.
springframework
.
data
.
redis
.
connection
.
Message
message
,
byte
[]
bytes
)
{
byte
[]
messageBody
=
message
.
getBody
();
// 手动序列化和反序列化,避免 redis 序列化不一致问题
Message
mqttMessage
=
JsonUtil
.
readValue
(
messageBody
,
Message
.
class
);
if
(
mqttMessage
==
null
)
{
return
;
}
String
clientId
=
mqttMessage
.
getClientId
();
String
topic
=
mqttMessage
.
getTopic
();
MqttQoS
mqttQoS
=
MqttQoS
.
valueOf
(
mqttMessage
.
getQos
());
boolean
retain
=
mqttMessage
.
isRetain
();
if
(
StringUtil
.
isBlank
(
clientId
))
{
mqttServer
.
publishAll
(
topic
,
ByteBuffer
.
wrap
(
mqttMessage
.
getPayload
()),
mqttQoS
,
retain
);
}
else
{
mqttServer
.
publish
(
clientId
,
topic
,
ByteBuffer
.
wrap
(
mqttMessage
.
getPayload
()),
mqttQoS
,
retain
);
}
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
byte
[]
channelBytes
=
RedisSerializer
.
string
().
serialize
(
channel
);
redisTemplate
.
execute
((
RedisCallback
<
Void
>)
connection
->
{
connection
.
subscribe
(
RedisMqttMessageReceiver
.
this
,
channelBytes
);
return
null
;
});
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/cluster/RedisMqttMessageStore.java
0 → 100644
浏览文件 @
6aadba08
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & 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.broker.cluster
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.iot.mqtt.broker.enums.RedisKeys
;
import
net.dreamlu.iot.mqtt.core.server.model.Message
;
import
net.dreamlu.iot.mqtt.core.server.store.IMqttMessageStore
;
import
net.dreamlu.mica.redis.cache.MicaRedisCache
;
/**
* redis mqtt 遗嘱和保留消息存储
*
* @author L.cm
*/
@RequiredArgsConstructor
public
class
RedisMqttMessageStore
implements
IMqttMessageStore
{
private
final
MicaRedisCache
redisCache
;
@Override
public
boolean
addWillMessage
(
String
clientId
,
Message
message
)
{
redisCache
.
set
(
RedisKeys
.
MESSAGE_STORE_WILL
.
getKey
(
clientId
),
message
);
return
true
;
}
@Override
public
boolean
clearWillMessage
(
String
clientId
)
{
redisCache
.
del
(
RedisKeys
.
MESSAGE_STORE_WILL
.
getKey
(
clientId
));
return
true
;
}
@Override
public
Message
getWillMessage
(
String
clientId
)
{
return
redisCache
.
get
(
RedisKeys
.
MESSAGE_STORE_WILL
.
getKey
(
clientId
));
}
@Override
public
boolean
addRetainMessage
(
String
topic
,
Message
message
)
{
redisCache
.
set
(
RedisKeys
.
MESSAGE_STORE_RETAIN
.
getKey
(
topic
),
message
);
return
true
;
}
@Override
public
boolean
clearRetainMessage
(
String
topic
)
{
redisCache
.
del
(
RedisKeys
.
MESSAGE_STORE_RETAIN
.
getKey
(
topic
));
return
true
;
}
@Override
public
Message
getRetainMessage
(
String
topic
)
{
return
null
;
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/config/MqttBrokerConfiguration.java
浏览文件 @
6aadba08
...
@@ -16,9 +16,15 @@
...
@@ -16,9 +16,15 @@
package
net.dreamlu.iot.mqtt.broker.config
;
package
net.dreamlu.iot.mqtt.broker.config
;
import
net.dreamlu.iot.mqtt.broker.cluster.RedisMqttMessageDispatcher
;
import
net.dreamlu.iot.mqtt.broker.cluster.RedisMqttMessageReceiver
;
import
net.dreamlu.iot.mqtt.broker.enums.RedisKeys
;
import
net.dreamlu.iot.mqtt.broker.listener.MqttBrokerConnectListener
;
import
net.dreamlu.iot.mqtt.broker.listener.MqttBrokerMessageListener
;
import
net.dreamlu.iot.mqtt.broker.listener.MqttBrokerMessageListener
;
import
net.dreamlu.iot.mqtt.core.server.MqttServer
;
import
net.dreamlu.iot.mqtt.core.server.dispatcher.IMqttMessageDispatcher
;
import
net.dreamlu.iot.mqtt.core.server.dispatcher.IMqttMessageDispatcher
;
import
net.dreamlu.iot.mqtt.core.server.support.DefaultMqttMessageDispatcher
;
import
net.dreamlu.iot.mqtt.core.server.event.IMqttConnectStatusListener
;
import
net.dreamlu.mica.redis.cache.MicaRedisCache
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -31,14 +37,24 @@ import org.springframework.context.annotation.Configuration;
...
@@ -31,14 +37,24 @@ import org.springframework.context.annotation.Configuration;
public
class
MqttBrokerConfiguration
{
public
class
MqttBrokerConfiguration
{
@Bean
@Bean
public
IMqttMessageDispatcher
messageDispatcher
()
{
public
IMqttConnectStatusListener
mqttBrokerConnectListener
(
MicaRedisCache
redisCache
)
{
// TODO L.cm 此处采用 redis 实现广播
return
new
MqttBrokerConnectListener
(
redisCache
,
RedisKeys
.
CONNECT_STATUS
.
getKey
());
return
new
DefaultMqttMessageDispatcher
();
}
}
@Bean
@Bean
public
MqttBrokerMessageListener
brokerMessageListener
(
IMqttMessageDispatcher
dispatcher
)
{
public
RedisMqttMessageReceiver
mqttMessageReceiver
(
MicaRedisCache
redisCache
,
return
new
MqttBrokerMessageListener
(
dispatcher
);
MqttServer
mqttServer
)
{
return
new
RedisMqttMessageReceiver
(
redisCache
,
RedisKeys
.
REDIS_CHANNEL
.
getKey
(),
mqttServer
);
}
@Bean
public
IMqttMessageDispatcher
mqttMessageDispatcher
(
MicaRedisCache
redisCache
)
{
return
new
RedisMqttMessageDispatcher
(
redisCache
,
RedisKeys
.
REDIS_CHANNEL
.
getKey
());
}
@Bean
public
MqttBrokerMessageListener
brokerMessageListener
(
IMqttMessageDispatcher
mqttMessageDispatcher
)
{
return
new
MqttBrokerMessageListener
(
mqttMessageDispatcher
);
}
}
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/config/package-info.java
已删除
100644 → 0
浏览文件 @
35be2f17
package
net.dreamlu.iot.mqtt.broker.config
;
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/enums/RedisKeys.java
0 → 100644
浏览文件 @
6aadba08
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & 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.broker.enums
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
/**
* redis key 汇总,方便统一处理
*
* @author L.cm
*/
@Getter
@RequiredArgsConstructor
public
enum
RedisKeys
{
/**
* mqtt <-> redis pug/sub 消息交互
*/
REDIS_CHANNEL
(
"mqtt:channel:exchange"
),
/**
* 连接状态存储
*/
CONNECT_STATUS
(
"mqtt:connect:status"
),
/**
* 遗嘱消息存储
*/
MESSAGE_STORE_WILL
(
"mqtt:messages:will:"
),
/**
* 保留消息存储
*/
MESSAGE_STORE_RETAIN
(
"mqtt:messages:retain:"
),
;
private
final
String
key
;
/**
* 用于拼接后缀
*
* @param suffix 后缀
* @return 完整的 redis key
*/
public
String
getKey
(
String
suffix
)
{
return
this
.
key
.
concat
(
suffix
);
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/listener/MqttBrokerConnectListener.java
浏览文件 @
6aadba08
...
@@ -16,21 +16,27 @@
...
@@ -16,21 +16,27 @@
package
net.dreamlu.iot.mqtt.broker.listener
;
package
net.dreamlu.iot.mqtt.broker.listener
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.iot.mqtt.core.server.event.IMqttConnectStatusListener
;
import
net.dreamlu.iot.mqtt.core.server.event.IMqttConnectStatusListener
;
import
net.dreamlu.mica.redis.cache.MicaRedisCache
;
/**
/**
* mqtt 连接监听
* mqtt 连接监听
*
*
* @author L.cm
* @author L.cm
*/
*/
@RequiredArgsConstructor
public
class
MqttBrokerConnectListener
implements
IMqttConnectStatusListener
{
public
class
MqttBrokerConnectListener
implements
IMqttConnectStatusListener
{
private
final
MicaRedisCache
redisCache
;
private
final
String
connectStatusKey
;
@Override
@Override
public
void
online
(
String
clientId
)
{
public
void
online
(
String
clientId
)
{
redisCache
.
sAdd
(
connectStatusKey
,
clientId
);
}
}
@Override
@Override
public
void
offline
(
String
clientId
)
{
public
void
offline
(
String
clientId
)
{
redisCache
.
sRem
(
connectStatusKey
,
clientId
);
}
}
}
}
mica-mqtt-broker/src/main/java/net/dreamlu/iot/mqtt/broker/listener/MqttBrokerMessageListener.java
浏览文件 @
6aadba08
...
@@ -46,7 +46,7 @@ public class MqttBrokerMessageListener implements IMqttMessageListener {
...
@@ -46,7 +46,7 @@ public class MqttBrokerMessageListener implements IMqttMessageListener {
message
.
setPayload
(
payload
.
array
());
message
.
setPayload
(
payload
.
array
());
}
}
message
.
setMessageType
(
MqttMessageType
.
PUBLISH
.
value
());
message
.
setMessageType
(
MqttMessageType
.
PUBLISH
.
value
());
message
.
set
StoreTime
(
System
.
currentTimeMillis
());
message
.
set
Timestamp
(
System
.
currentTimeMillis
());
dispatcher
.
send
(
message
);
dispatcher
.
send
(
message
);
}
}
}
}
mica-mqtt-broker/src/main/resources/application.yml
浏览文件 @
6aadba08
...
@@ -22,6 +22,7 @@ management:
...
@@ -22,6 +22,7 @@ management:
web
:
web
:
exposure
:
exposure
:
include
:
'
*'
include
:
'
*'
# 日志配置
logging
:
logging
:
level
:
level
:
root
:
info
root
:
info
...
...
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/model/Message.java
浏览文件 @
6aadba08
...
@@ -58,7 +58,7 @@ public class Message implements Serializable {
...
@@ -58,7 +58,7 @@ public class Message implements Serializable {
/**
/**
* 存储时间
* 存储时间
*/
*/
private
long
storeTime
;
private
long
timestamp
;
public
String
getClientId
()
{
public
String
getClientId
()
{
return
clientId
;
return
clientId
;
...
@@ -116,12 +116,12 @@ public class Message implements Serializable {
...
@@ -116,12 +116,12 @@ public class Message implements Serializable {
this
.
payload
=
payload
;
this
.
payload
=
payload
;
}
}
public
long
get
StoreTime
()
{
public
long
get
Timestamp
()
{
return
storeTime
;
return
timestamp
;
}
}
public
void
set
StoreTime
(
long
storeTime
)
{
public
void
set
Timestamp
(
long
timestamp
)
{
this
.
storeTime
=
storeTime
;
this
.
timestamp
=
timestamp
;
}
}
@Override
@Override
...
@@ -137,7 +137,7 @@ public class Message implements Serializable {
...
@@ -137,7 +137,7 @@ public class Message implements Serializable {
qos
==
message
.
qos
&&
qos
==
message
.
qos
&&
retain
==
message
.
retain
&&
retain
==
message
.
retain
&&
dup
==
message
.
dup
&&
dup
==
message
.
dup
&&
storeTime
==
message
.
storeTime
&&
timestamp
==
message
.
timestamp
&&
Objects
.
equals
(
clientId
,
message
.
clientId
)
&&
Objects
.
equals
(
clientId
,
message
.
clientId
)
&&
Objects
.
equals
(
topic
,
message
.
topic
)
&&
Objects
.
equals
(
topic
,
message
.
topic
)
&&
Arrays
.
equals
(
payload
,
message
.
payload
);
Arrays
.
equals
(
payload
,
message
.
payload
);
...
@@ -145,7 +145,7 @@ public class Message implements Serializable {
...
@@ -145,7 +145,7 @@ public class Message implements Serializable {
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
int
result
=
Objects
.
hash
(
clientId
,
messageType
,
topic
,
qos
,
retain
,
dup
,
storeTime
);
int
result
=
Objects
.
hash
(
clientId
,
messageType
,
topic
,
qos
,
retain
,
dup
,
timestamp
);
result
=
31
*
result
+
Arrays
.
hashCode
(
payload
);
result
=
31
*
result
+
Arrays
.
hashCode
(
payload
);
return
result
;
return
result
;
}
}
...
@@ -160,7 +160,7 @@ public class Message implements Serializable {
...
@@ -160,7 +160,7 @@ public class Message implements Serializable {
", retain="
+
retain
+
", retain="
+
retain
+
", dup="
+
dup
+
", dup="
+
dup
+
", payload="
+
Arrays
.
toString
(
payload
)
+
", payload="
+
Arrays
.
toString
(
payload
)
+
",
storeTime="
+
storeTime
+
",
timestamp="
+
timestamp
+
'}'
;
'}'
;
}
}
}
}
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/store/IMqttMessageStore.java
浏览文件 @
6aadba08
...
@@ -70,9 +70,9 @@ public interface IMqttMessageStore {
...
@@ -70,9 +70,9 @@ public interface IMqttMessageStore {
/**
/**
* 获取所有 retain 消息
* 获取所有 retain 消息
*
*
* @param topic
topic
* @param topic
Filter topicFilter
* @return Message
* @return Message
*/
*/
Message
getRetainMessage
(
String
topic
);
Message
getRetainMessage
(
String
topic
Filter
);
}
}
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/store/InMemoryMqttMessageStore.java
浏览文件 @
6aadba08
...
@@ -67,8 +67,9 @@ public class InMemoryMqttMessageStore implements IMqttMessageStore {
...
@@ -67,8 +67,9 @@ public class InMemoryMqttMessageStore implements IMqttMessageStore {
}
}
@Override
@Override
public
Message
getRetainMessage
(
String
topic
)
{
public
Message
getRetainMessage
(
String
topicFilter
)
{
return
retainStore
.
get
(
topic
);
// TODO L.cm 改成匹配
return
retainStore
.
get
(
topicFilter
);
}
}
}
}
mica-mqtt-core/src/main/java/net/dreamlu/iot/mqtt/core/server/support/DefaultMqttServerProcessor.java
浏览文件 @
6aadba08
...
@@ -270,7 +270,7 @@ public class DefaultMqttServerProcessor implements MqttServerProcessor {
...
@@ -270,7 +270,7 @@ public class DefaultMqttServerProcessor implements MqttServerProcessor {
topicList
.
add
(
topicName
);
topicList
.
add
(
topicName
);
sessionManager
.
addSubscribe
(
topicName
,
clientId
,
mqttQoS
);
sessionManager
.
addSubscribe
(
topicName
,
clientId
,
mqttQoS
);
}
}
logger
.
info
(
"Subscribe - clientId:{} Topic:{} mqttQoS:{} messageId:{}"
,
clientId
,
topicList
,
mqttQosList
,
messageId
);
logger
.
info
(
"Subscribe - clientId:{} Topic
Filters
:{} mqttQoS:{} messageId:{}"
,
clientId
,
topicList
,
mqttQosList
,
messageId
);
// 3. 返回 ack
// 3. 返回 ack
MqttMessage
subAckMessage
=
MqttMessageBuilders
.
subAck
()
MqttMessage
subAckMessage
=
MqttMessageBuilders
.
subAck
()
.
addGrantedQosList
(
mqttQosList
)
.
addGrantedQosList
(
mqttQosList
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录