Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
25ba6fab
R
Rocketmq
项目概览
小五666\n哈哈
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
25ba6fab
编写于
5月 14, 2019
作者:
C
chengxiangwang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize logic of push message to consumers;add MQTTSession(extends Client)
上级
f8da6ffa
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
33 addition
and
26 deletion
+33
-26
common/src/main/java/org/apache/rocketmq/common/client/Client.java
...c/main/java/org/apache/rocketmq/common/client/Client.java
+10
-0
mqtt/src/main/java/org/apache/rocketmq/mqtt/client/InFlightMessage.java
...java/org/apache/rocketmq/mqtt/client/InFlightMessage.java
+3
-4
mqtt/src/main/java/org/apache/rocketmq/mqtt/client/MQTTSession.java
...ain/java/org/apache/rocketmq/mqtt/client/MQTTSession.java
+17
-14
mqtt/src/main/java/org/apache/rocketmq/mqtt/constant/MqttConstant.java
.../java/org/apache/rocketmq/mqtt/constant/MqttConstant.java
+1
-0
mqtt/src/main/java/org/apache/rocketmq/mqtt/mqtthandler/impl/MqttConnectMessageHandler.java
...etmq/mqtt/mqtthandler/impl/MqttConnectMessageHandler.java
+2
-8
未找到文件。
common/src/main/java/org/apache/rocketmq/common/client/Client.java
浏览文件 @
25ba6fab
...
...
@@ -41,7 +41,17 @@ public class Client {
private
String
snodeAddress
;
public
Client
()
{
}
public
Client
(
String
clientId
,
ClientRole
clientRole
,
Set
<
String
>
groups
,
RemotingChannel
remotingChannel
,
long
lastUpdateTimestamp
)
{
this
.
clientId
=
clientId
;
this
.
clientRole
=
clientRole
;
this
.
groups
=
groups
;
this
.
remotingChannel
=
remotingChannel
;
this
.
lastUpdateTimestamp
=
lastUpdateTimestamp
;
}
public
ClientRole
getClientRole
()
{
return
clientRole
;
...
...
mqtt/src/main/java/org/apache/rocketmq/mqtt/client/InFlightMessage.java
浏览文件 @
25ba6fab
...
...
@@ -17,16 +17,15 @@
package
org.apache.rocketmq.mqtt.client
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.handler.codec.mqtt.MqttQoS
;
public
class
InFlightMessage
{
final
String
topic
;
final
MqttQoS
publishing
Qos
;
final
Integer
push
Qos
;
final
ByteBuf
payload
;
InFlightMessage
(
String
topic
,
MqttQoS
publishing
Qos
,
ByteBuf
payload
)
{
InFlightMessage
(
String
topic
,
Integer
push
Qos
,
ByteBuf
payload
)
{
this
.
topic
=
topic
;
this
.
pu
blishingQos
=
publishing
Qos
;
this
.
pu
shQos
=
push
Qos
;
this
.
payload
=
payload
;
}
}
mqtt/src/main/java/org/apache/rocketmq/mqtt/client/MQTTSession.java
浏览文件 @
25ba6fab
...
...
@@ -17,21 +17,20 @@
package
org.apache.rocketmq.mqtt.client
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.handler.codec.mqtt.MqttPublishMessage
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Hashtable
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.
concurrent.ConcurrentHashMap
;
import
java.util.
Set
;
import
java.util.concurrent.DelayQueue
;
import
java.util.concurrent.Delayed
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.apache.rocketmq.common.client.Client
;
import
org.apache.rocketmq.common.client.
Subscription
;
import
org.apache.rocketmq.common.client.
ClientRole
;
import
org.apache.rocketmq.mqtt.exception.MqttRuntimeException
;
import
org.apache.rocketmq.mqtt.processor.DefaultMqttMessageProcessor
;
import
org.apache.rocketmq.remoting.RemotingChannel
;
import
org.apache.rocketmq.remoting.transport.mqtt.MqttHeader
;
public
class
MQTTSession
extends
Client
{
...
...
@@ -41,6 +40,7 @@ public class MQTTSession extends Client {
private
final
AtomicInteger
inflightSlots
=
new
AtomicInteger
(
10
);
private
final
Map
<
Integer
,
InFlightMessage
>
inflightWindow
=
new
HashMap
<>();
private
final
DelayQueue
<
InFlightPacket
>
inflightTimeouts
=
new
DelayQueue
<>();
private
static
final
int
FLIGHT_BEFORE_RESEND_MS
=
5_000
;
private
final
AtomicInteger
lastPacketId
=
new
AtomicInteger
(
0
);
private
Hashtable
inUsePacketIds
=
new
Hashtable
();
private
int
nextPacketId
=
0
;
...
...
@@ -74,6 +74,13 @@ public class MQTTSession extends Client {
}
}
public
MQTTSession
(
String
clientId
,
ClientRole
clientRole
,
Set
<
String
>
groups
,
boolean
isConnected
,
boolean
cleanSession
,
RemotingChannel
remotingChannel
,
long
lastUpdateTimestamp
)
{
super
(
clientId
,
clientRole
,
groups
,
remotingChannel
,
lastUpdateTimestamp
);
this
.
isConnected
=
isConnected
;
this
.
cleanSession
=
cleanSession
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
...
...
@@ -114,21 +121,17 @@ public class MQTTSession extends Client {
DefaultMqttMessageProcessor
defaultMqttMessageProcessor
)
{
if
(
mqttHeader
.
getQosLevel
()
>
0
)
{
// IOTClientManagerImpl iotClientManager = (IOTClientManagerImpl) defaultMqttMessageProcessor.getIotClientManager();
// ConcurrentHashMap<String, Subscription> clientId2Subscription = iotClientManager.getClientId2Subscription();
// Subscription subscription = clientId2Subscription.get(this.getClientId());
// Enumeration<String> topicFilters = subscription.getSubscriptionTable().keys();
// while (topicFilters.hasMoreElements()) {
// String topicFilter = topicFilters.nextElement();
// }
inflightSlots
.
decrementAndGet
();
mqttHeader
.
setPacketId
(
getNextPacketId
());
inflightWindow
.
put
(
mqttHeader
.
getPacketId
(),
new
InFlightMessage
(
mqttHeader
.
getTopicName
(),
));
inflightWindow
.
put
(
mqttHeader
.
getPacketId
(),
new
InFlightMessage
(
mqttHeader
.
getTopicName
(),
mqttHeader
.
getQosLevel
(),
payload
));
inflightTimeouts
.
add
(
new
InFlightPacket
(
mqttHeader
.
getPacketId
(),
FLIGHT_BEFORE_RESEND_MS
));
}
defaultMqttMessageProcessor
.
getMqttPushService
().
pushMessageQos
(
mqttHeader
,
payload
,
this
);
}
public
void
pubAckReceived
(
int
ackPacketId
)
{
inflightWindow
.
remove
(
ackPacketId
);
inflightSlots
.
incrementAndGet
();
}
private
synchronized
void
releasePacketId
(
int
msgId
)
{
this
.
inUsePacketIds
.
remove
(
new
Integer
(
msgId
));
}
...
...
mqtt/src/main/java/org/apache/rocketmq/mqtt/constant/MqttConstant.java
浏览文件 @
25ba6fab
...
...
@@ -26,5 +26,6 @@ public class MqttConstant {
public
static
final
String
SUBSCRIPTION_FLAG_SHARP
=
"#"
;
public
static
final
String
SUBSCRIPTION_SEPARATOR
=
"/"
;
public
static
final
long
DEFAULT_TIMEOUT_MILLS
=
3000L
;
public
static
final
String
PROPERTY_MQTT_QOS
=
"PROPERTY_MQTT_QOS"
;
public
static
final
AttributeKey
<
Client
>
MQTT_CLIENT_ATTRIBUTE_KEY
=
AttributeKey
.
valueOf
(
"mqtt.client"
);
}
mqtt/src/main/java/org/apache/rocketmq/mqtt/mqtthandler/impl/MqttConnectMessageHandler.java
浏览文件 @
25ba6fab
...
...
@@ -117,17 +117,11 @@ public class MqttConnectMessageHandler implements MessageHandler {
}
}
MQTTSession
client
=
new
MQTTSession
();
client
.
setClientId
(
payload
.
clientIdentifier
());
client
.
setClientRole
(
ClientRole
.
IOTCLIENT
);
client
.
setGroups
(
new
HashSet
<
String
>()
{
MQTTSession
client
=
new
MQTTSession
(
payload
.
clientIdentifier
(),
ClientRole
.
IOTCLIENT
,
new
HashSet
<
String
>()
{
{
add
(
"IOT_GROUP"
);
}
});
client
.
setConnected
(
true
);
client
.
setRemotingChannel
(
remotingChannel
);
client
.
setLastUpdateTimestamp
(
System
.
currentTimeMillis
());
},
true
,
mqttConnectMessage
.
variableHeader
().
isCleanSession
(),
remotingChannel
,
System
.
currentTimeMillis
());
//register remotingChannel<--->client
iotClientManager
.
register
(
IOTClientManagerImpl
.
IOT_GROUP
,
client
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录