Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
7f234337
R
Rocketmq
项目概览
s920243400
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
1
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看板
提交
7f234337
编写于
1月 30, 2019
作者:
C
chengxiangwang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize logic with dispatcher;add some test case
上级
4d88d5b4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
273 addition
and
39 deletion
+273
-39
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java
...rg/apache/rocketmq/remoting/protocol/RemotingCommand.java
+0
-30
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/MqttMessage2RemotingCommandHandler.java
...ng/transport/mqtt/MqttMessage2RemotingCommandHandler.java
+54
-0
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/MqttRemotingClient.java
.../rocketmq/remoting/transport/mqtt/MqttRemotingClient.java
+6
-6
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/MqttRemotingServer.java
.../rocketmq/remoting/transport/mqtt/MqttRemotingServer.java
+2
-2
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/RemotingCommand2MqttMessageHandler.java
...ng/transport/mqtt/RemotingCommand2MqttMessageHandler.java
+1
-1
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/EncodeDecodeDispatcher.java
...ing/transport/mqtt/dispatcher/EncodeDecodeDispatcher.java
+49
-0
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/Message2MessageEncodeDecode.java
...ransport/mqtt/dispatcher/Message2MessageEncodeDecode.java
+28
-0
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/MqttConnectEncodeDecode.java
...ng/transport/mqtt/dispatcher/MqttConnectEncodeDecode.java
+70
-0
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/MqttConnectackEncodeDecode.java
...transport/mqtt/dispatcher/MqttConnectackEncodeDecode.java
+34
-0
snode/src/test/java/org/apache/rocketmq/snode/processor/MqttConnectMessageHandlerTest.java
...cketmq/snode/processor/MqttConnectMessageHandlerTest.java
+29
-0
未找到文件。
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java
浏览文件 @
7f234337
...
@@ -17,8 +17,6 @@
...
@@ -17,8 +17,6 @@
package
org.apache.rocketmq.remoting.protocol
;
package
org.apache.rocketmq.remoting.protocol
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -176,34 +174,6 @@ public class RemotingCommand {
...
@@ -176,34 +174,6 @@ public class RemotingCommand {
return
CodecHelper
.
decodeCommandCustomHeader
(
this
,
classHeader
);
return
CodecHelper
.
decodeCommandCustomHeader
(
this
,
classHeader
);
}
}
public
void
makeCustomHeaderToNet
()
{
if
(
this
.
customHeader
!=
null
)
{
Field
[]
fields
=
customHeader
.
getClass
().
getDeclaredFields
();
if
(
null
==
this
.
extFields
)
{
this
.
extFields
=
new
HashMap
<
String
,
String
>();
}
for
(
Field
field
:
fields
)
{
if
(!
Modifier
.
isStatic
(
field
.
getModifiers
()))
{
String
name
=
field
.
getName
();
if
(!
name
.
startsWith
(
"this"
))
{
Object
value
=
null
;
try
{
field
.
setAccessible
(
true
);
value
=
field
.
get
(
this
.
customHeader
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Failed to access field [{}]"
,
name
,
e
);
}
if
(
value
!=
null
)
{
this
.
extFields
.
put
(
name
,
value
.
toString
());
}
}
}
}
}
}
public
ByteBuffer
encodeHeader
(
final
int
bodyLength
)
{
public
ByteBuffer
encodeHeader
(
final
int
bodyLength
)
{
return
CodecHelper
.
encodeHeader
(
bodyLength
,
this
);
return
CodecHelper
.
encodeHeader
(
bodyLength
,
this
);
}
}
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/Mqtt2RemotingCommandHandler.java
→
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/Mqtt
Message
2RemotingCommandHandler.java
浏览文件 @
7f234337
...
@@ -17,19 +17,15 @@
...
@@ -17,19 +17,15 @@
package
org.apache.rocketmq.remoting.transport.mqtt
;
package
org.apache.rocketmq.remoting.transport.mqtt
;
import
com.alibaba.fastjson.JSON
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.handler.codec.MessageToMessageDecoder
;
import
io.netty.handler.codec.MessageToMessageDecoder
;
import
io.netty.handler.codec.mqtt.MqttConnectMessage
;
import
io.netty.handler.codec.mqtt.MqttConnectVariableHeader
;
import
io.netty.handler.codec.mqtt.MqttFixedHeader
;
import
io.netty.handler.codec.mqtt.MqttMessage
;
import
io.netty.handler.codec.mqtt.MqttMessage
;
import
java.nio.charset.Charset
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.rocketmq.remoting.common.RemotingUtil
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.transport.mqtt.dispatcher.EncodeDecodeDispatcher
;
import
org.apache.rocketmq.remoting.transport.mqtt.dispatcher.Message2MessageEncodeDecode
;
public
class
Mqtt2RemotingCommandHandler
extends
MessageToMessageDecoder
<
MqttMessage
>
{
public
class
Mqtt
Message
2RemotingCommandHandler
extends
MessageToMessageDecoder
<
MqttMessage
>
{
/**
/**
* Decode from one message to an other. This method will be called for each written message that
* Decode from one message to an other. This method will be called for each written message that
...
@@ -48,59 +44,11 @@ public class Mqtt2RemotingCommandHandler extends MessageToMessageDecoder<MqttMes
...
@@ -48,59 +44,11 @@ public class Mqtt2RemotingCommandHandler extends MessageToMessageDecoder<MqttMes
return
;
return
;
}
}
RemotingCommand
requestCommand
=
null
;
RemotingCommand
requestCommand
=
null
;
MqttFixedHeader
mqttFixedHeader
=
msg
.
fixedHeader
();
Message2MessageEncodeDecode
message2MessageEncodeDecode
=
EncodeDecodeDispatcher
Object
variableHeader
=
msg
.
variableHeader
();
.
getEncodeDecodeDispatcher
().
get
(
msg
.
fixedHeader
().
messageType
());
if
(
message2MessageEncodeDecode
!=
null
)
{
switch
(
msg
.
fixedHeader
().
messageType
())
{
requestCommand
=
message2MessageEncodeDecode
.
decode
(
msg
);
case
CONNECT:
RocketMQMqttConnectPayload
payload
=
RocketMQMqttConnectPayload
.
fromMqttConnectPayload
(((
MqttConnectMessage
)
msg
).
payload
());
MqttHeader
mqttHeader
=
new
MqttHeader
();
mqttHeader
.
setMessageType
(
mqttFixedHeader
.
messageType
().
value
());
mqttHeader
.
setDup
(
mqttFixedHeader
.
isDup
());
mqttHeader
.
setQosLevel
(
mqttFixedHeader
.
qosLevel
().
value
());
mqttHeader
.
setRetain
(
mqttFixedHeader
.
isRetain
());
mqttHeader
.
setRemainingLength
(
mqttFixedHeader
.
remainingLength
());
MqttConnectVariableHeader
mqttConnectVariableHeader
=
(
MqttConnectVariableHeader
)
variableHeader
;
mqttHeader
.
setName
(
mqttConnectVariableHeader
.
name
());
mqttHeader
.
setVersion
(
mqttConnectVariableHeader
.
version
());
mqttHeader
.
setHasUserName
(
mqttConnectVariableHeader
.
hasUserName
());
mqttHeader
.
setHasPassword
(
mqttConnectVariableHeader
.
hasPassword
());
mqttHeader
.
setWillRetain
(
mqttConnectVariableHeader
.
isWillRetain
());
mqttHeader
.
setWillQos
(
mqttConnectVariableHeader
.
willQos
());
mqttHeader
.
setWillFlag
(
mqttConnectVariableHeader
.
isWillFlag
());
mqttHeader
.
setCleanSession
(
mqttConnectVariableHeader
.
isCleanSession
());
mqttHeader
.
setKeepAliveTimeSeconds
(
mqttConnectVariableHeader
.
keepAliveTimeSeconds
());
requestCommand
=
RemotingCommand
.
createRequestCommand
(
1000
,
mqttHeader
);
requestCommand
.
makeCustomHeaderToNet
();
requestCommand
.
setBody
(
payload
.
encode
());
out
.
add
(
requestCommand
);
case
CONNACK:
case
DISCONNECT:
case
PUBLISH:
case
PUBACK:
case
PUBREC:
case
PUBREL:
case
PUBCOMP:
case
SUBSCRIBE:
case
SUBACK:
case
UNSUBSCRIBE:
case
UNSUBACK:
case
PINGREQ:
case
PINGRESP:
}
}
private
byte
[]
encode
(
Object
obj
)
{
String
json
=
JSON
.
toJSONString
(
obj
,
false
);
if
(
json
!=
null
)
{
return
json
.
getBytes
(
Charset
.
forName
(
RemotingUtil
.
REMOTING_CHARSET
));
}
}
return
null
;
out
.
add
(
requestCommand
)
;
}
}
}
}
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/MqttRemotingClient.java
浏览文件 @
7f234337
...
@@ -188,22 +188,22 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
...
@@ -188,22 +188,22 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
try
{
try
{
long
costTime
=
System
.
currentTimeMillis
()
-
beginStartTime
;
long
costTime
=
System
.
currentTimeMillis
()
-
beginStartTime
;
if
(
timeoutMillis
<
costTime
)
{
if
(
timeoutMillis
<
costTime
)
{
throw
new
RemotingTimeoutException
(
"
i
nvokeSync call timeout"
);
throw
new
RemotingTimeoutException
(
"
I
nvokeSync call timeout"
);
}
}
RemotingCommand
response
=
this
.
invokeSyncWithInterceptor
(
remotingChannel
,
request
,
timeoutMillis
-
costTime
);
RemotingCommand
response
=
this
.
invokeSyncWithInterceptor
(
remotingChannel
,
request
,
timeoutMillis
-
costTime
);
return
response
;
return
response
;
}
catch
(
RemotingException
remotingException
)
{
}
catch
(
RemotingException
remotingException
)
{
if
(
remotingException
instanceof
RemotingSendRequestException
)
{
if
(
remotingException
instanceof
RemotingSendRequestException
)
{
log
.
warn
(
"
i
nvokeSync: send request exception, so close the channel[{}]"
,
addr
);
log
.
warn
(
"
I
nvokeSync: send request exception, so close the channel[{}]"
,
addr
);
this
.
closeRemotingChannel
(
addr
,
remotingChannel
);
this
.
closeRemotingChannel
(
addr
,
remotingChannel
);
throw
(
RemotingSendRequestException
)
remotingException
;
throw
(
RemotingSendRequestException
)
remotingException
;
}
}
if
(
remotingException
instanceof
RemotingTimeoutException
)
{
if
(
remotingException
instanceof
RemotingTimeoutException
)
{
if
(
nettyClientConfig
.
isClientCloseSocketIfTimeout
())
{
if
(
nettyClientConfig
.
isClientCloseSocketIfTimeout
())
{
this
.
closeRemotingChannel
(
addr
,
remotingChannel
);
this
.
closeRemotingChannel
(
addr
,
remotingChannel
);
log
.
warn
(
"
i
nvokeSync: close socket because of timeout, {}ms, {}"
,
timeoutMillis
,
addr
);
log
.
warn
(
"
I
nvokeSync: close socket because of timeout, {}ms, {}"
,
timeoutMillis
,
addr
);
}
}
log
.
warn
(
"
i
nvokeSync: wait response timeout exception, the channel[{}]"
,
addr
);
log
.
warn
(
"
I
nvokeSync: wait response timeout exception, the channel[{}]"
,
addr
);
throw
(
RemotingTimeoutException
)
remotingException
;
throw
(
RemotingTimeoutException
)
remotingException
;
}
}
}
}
...
@@ -229,11 +229,11 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
...
@@ -229,11 +229,11 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
try
{
try
{
long
costTime
=
System
.
currentTimeMillis
()
-
beginStartTime
;
long
costTime
=
System
.
currentTimeMillis
()
-
beginStartTime
;
if
(
timeoutMillis
<
costTime
)
{
if
(
timeoutMillis
<
costTime
)
{
throw
new
RemotingTooMuchRequestException
(
"
i
nvokeAsync call timeout"
);
throw
new
RemotingTooMuchRequestException
(
"
I
nvokeAsync call timeout"
);
}
}
this
.
invokeAsyncImpl
(
channel
,
request
,
timeoutMillis
-
costTime
,
invokeCallback
);
this
.
invokeAsyncImpl
(
channel
,
request
,
timeoutMillis
-
costTime
,
invokeCallback
);
}
catch
(
RemotingSendRequestException
e
)
{
}
catch
(
RemotingSendRequestException
e
)
{
log
.
warn
(
"
i
nvokeAsync: send request exception, so close the channel[{}]"
,
addr
);
log
.
warn
(
"
I
nvokeAsync: send request exception, so close the channel[{}]"
,
addr
);
this
.
closeChannel
(
addr
,
channel
);
this
.
closeChannel
(
addr
,
channel
);
throw
e
;
throw
e
;
}
}
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/MqttRemotingServer.java
浏览文件 @
7f234337
...
@@ -182,8 +182,8 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
...
@@ -182,8 +182,8 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
.
addLast
(
defaultEventExecutorGroup
,
.
addLast
(
defaultEventExecutorGroup
,
new
MqttDecoder
(),
new
MqttDecoder
(),
MqttEncoder
.
INSTANCE
,
MqttEncoder
.
INSTANCE
,
new
Mqtt2RemotingCommandHandler
(),
new
Mqtt
Message
2RemotingCommandHandler
(),
new
RemotingCommand2MqttHandler
(),
new
RemotingCommand2Mqtt
Message
Handler
(),
new
IdleStateHandler
(
nettyServerConfig
new
IdleStateHandler
(
nettyServerConfig
.
getConnectionChannelReaderIdleSeconds
(),
.
getConnectionChannelReaderIdleSeconds
(),
nettyServerConfig
nettyServerConfig
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/RemotingCommand2MqttHandler.java
→
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/RemotingCommand2Mqtt
Message
Handler.java
浏览文件 @
7f234337
...
@@ -22,7 +22,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
...
@@ -22,7 +22,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
import
java.util.List
;
import
java.util.List
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
public
class
RemotingCommand2MqttHandler
extends
MessageToMessageEncoder
<
RemotingCommand
>
{
public
class
RemotingCommand2Mqtt
Message
Handler
extends
MessageToMessageEncoder
<
RemotingCommand
>
{
/**
/**
* Encode from one message to an other. This method will be called for each written message that
* Encode from one message to an other. This method will be called for each written message that
...
...
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/EncodeDecodeDispatcher.java
0 → 100644
浏览文件 @
7f234337
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
org.apache.rocketmq.remoting.transport.mqtt.dispatcher
;
import
io.netty.handler.codec.mqtt.MqttMessageType
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
EncodeDecodeDispatcher
{
private
static
Map
<
MqttMessageType
,
Message2MessageEncodeDecode
>
encodeDecodeDispatcher
=
new
HashMap
<>();
static
{
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
CONNECT
,
new
MqttConnectEncodeDecode
());
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
CONNACK
,
new
MqttConnectackEncodeDecode
());
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
DISCONNECT
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PUBLISH
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PUBACK
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PUBREC
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PUBREL
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PUBCOMP
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
SUBSCRIBE
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
SUBACK
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
UNSUBSCRIBE
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
UNSUBACK
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PINGREQ
,
null
);
encodeDecodeDispatcher
.
put
(
MqttMessageType
.
PINGRESP
,
null
);
}
public
static
Map
<
MqttMessageType
,
Message2MessageEncodeDecode
>
getEncodeDecodeDispatcher
()
{
return
encodeDecodeDispatcher
;
}
}
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/Message2MessageEncodeDecode.java
0 → 100644
浏览文件 @
7f234337
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
org.apache.rocketmq.remoting.transport.mqtt.dispatcher
;
import
io.netty.handler.codec.mqtt.MqttMessage
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
public
interface
Message2MessageEncodeDecode
{
RemotingCommand
decode
(
MqttMessage
mqttMessage
);
MqttMessage
encode
(
RemotingCommand
remotingCommand
);
}
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/MqttConnectEncodeDecode.java
0 → 100644
浏览文件 @
7f234337
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
org.apache.rocketmq.remoting.transport.mqtt.dispatcher
;
import
io.netty.handler.codec.mqtt.MqttConnectMessage
;
import
io.netty.handler.codec.mqtt.MqttConnectVariableHeader
;
import
io.netty.handler.codec.mqtt.MqttFixedHeader
;
import
io.netty.handler.codec.mqtt.MqttMessage
;
import
org.apache.rocketmq.remoting.netty.CodecHelper
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.transport.mqtt.MqttHeader
;
import
org.apache.rocketmq.remoting.transport.mqtt.RocketMQMqttConnectPayload
;
public
class
MqttConnectEncodeDecode
implements
Message2MessageEncodeDecode
{
@Override
public
RemotingCommand
decode
(
MqttMessage
mqttMessage
)
{
RocketMQMqttConnectPayload
payload
=
RocketMQMqttConnectPayload
.
fromMqttConnectPayload
(((
MqttConnectMessage
)
mqttMessage
).
payload
());
RemotingCommand
requestCommand
=
null
;
MqttFixedHeader
mqttFixedHeader
=
mqttMessage
.
fixedHeader
();
MqttConnectVariableHeader
variableHeader
=
(
MqttConnectVariableHeader
)
mqttMessage
.
variableHeader
();
MqttHeader
mqttHeader
=
new
MqttHeader
();
mqttHeader
.
setMessageType
(
mqttFixedHeader
.
messageType
().
value
());
mqttHeader
.
setDup
(
mqttFixedHeader
.
isDup
());
mqttHeader
.
setQosLevel
(
mqttFixedHeader
.
qosLevel
().
value
());
mqttHeader
.
setRetain
(
mqttFixedHeader
.
isRetain
());
mqttHeader
.
setRemainingLength
(
mqttFixedHeader
.
remainingLength
());
mqttHeader
.
setName
(
variableHeader
.
name
());
mqttHeader
.
setVersion
(
variableHeader
.
version
());
mqttHeader
.
setHasUserName
(
variableHeader
.
hasUserName
());
mqttHeader
.
setHasPassword
(
variableHeader
.
hasPassword
());
mqttHeader
.
setWillRetain
(
variableHeader
.
isWillRetain
());
mqttHeader
.
setWillQos
(
variableHeader
.
willQos
());
mqttHeader
.
setWillFlag
(
variableHeader
.
isWillFlag
());
mqttHeader
.
setCleanSession
(
variableHeader
.
isCleanSession
());
mqttHeader
.
setKeepAliveTimeSeconds
(
variableHeader
.
keepAliveTimeSeconds
());
requestCommand
=
RemotingCommand
.
createRequestCommand
(
1000
,
mqttHeader
);
CodecHelper
.
makeCustomHeaderToNet
(
requestCommand
);
requestCommand
.
setBody
(
payload
.
encode
());
return
requestCommand
;
}
@Override
public
MqttMessage
encode
(
RemotingCommand
remotingCommand
)
{
return
null
;
}
}
remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/dispatcher/MqttConnectackEncodeDecode.java
0 → 100644
浏览文件 @
7f234337
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
org.apache.rocketmq.remoting.transport.mqtt.dispatcher
;
import
io.netty.handler.codec.mqtt.MqttMessage
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
public
class
MqttConnectackEncodeDecode
implements
Message2MessageEncodeDecode
{
@Override
public
RemotingCommand
decode
(
MqttMessage
mqttMessage
)
{
return
null
;
}
@Override
public
MqttMessage
encode
(
RemotingCommand
remotingCommand
)
{
return
null
;
}
}
snode/src/test/java/org/apache/rocketmq/snode/processor/MqttConnectMessageHandlerTest.java
浏览文件 @
7f234337
...
@@ -16,10 +16,39 @@
...
@@ -16,10 +16,39 @@
*/
*/
package
org.apache.rocketmq.snode.processor
;
package
org.apache.rocketmq.snode.processor
;
import
io.netty.handler.codec.mqtt.MqttConnectMessage
;
import
io.netty.handler.codec.mqtt.MqttConnectPayload
;
import
io.netty.handler.codec.mqtt.MqttConnectVariableHeader
;
import
io.netty.handler.codec.mqtt.MqttFixedHeader
;
import
io.netty.handler.codec.mqtt.MqttMessageType
;
import
io.netty.handler.codec.mqtt.MqttQoS
;
import
org.apache.rocketmq.remoting.ClientConfig
;
import
org.apache.rocketmq.remoting.RemotingChannel
;
import
org.apache.rocketmq.remoting.ServerConfig
;
import
org.apache.rocketmq.snode.SnodeController
;
import
org.apache.rocketmq.snode.config.SnodeConfig
;
import
org.apache.rocketmq.snode.processor.mqtthandler.MqttConnectMessageHandler
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MqttConnectMessageHandlerTest
{
public
class
MqttConnectMessageHandlerTest
{
@Mock
private
RemotingChannel
remotingChannel
;
@Test
public
void
testHandlerMessage
()
throws
Exception
{
MqttConnectMessageHandler
mqttConnectMessageHandler
=
new
MqttConnectMessageHandler
(
new
SnodeController
(
new
ServerConfig
(),
new
ClientConfig
(),
new
SnodeConfig
()));
MqttConnectPayload
payload
=
new
MqttConnectPayload
(
"1234567"
,
"testTopic"
,
"willMessage"
.
getBytes
(),
null
,
"1234567"
.
getBytes
());
MqttConnectMessage
mqttConnectMessage
=
new
MqttConnectMessage
(
new
MqttFixedHeader
(
MqttMessageType
.
CONNECT
,
false
,
MqttQoS
.
AT_MOST_ONCE
,
false
,
200
),
new
MqttConnectVariableHeader
(
null
,
4
,
false
,
false
,
false
,
0
,
false
,
false
,
50
),
new
MqttConnectPayload
(
"abcd"
,
"ttest"
,
"message"
.
getBytes
(),
"user"
,
"password"
.
getBytes
()));
mqttConnectMessageHandler
.
handleMessage
(
mqttConnectMessage
,
remotingChannel
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录