Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
2fb8b5f2
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
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看板
提交
2fb8b5f2
编写于
1月 09, 2019
作者:
D
duhenglucky
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add consumer group management for push module
上级
41366dda
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
89 addition
and
53 deletion
+89
-53
snode/src/main/java/org/apache/rocketmq/snode/client/ClientHousekeepingService.java
...ache/rocketmq/snode/client/ClientHousekeepingService.java
+4
-4
snode/src/main/java/org/apache/rocketmq/snode/client/ConsumerGroupInfo.java
...a/org/apache/rocketmq/snode/client/ConsumerGroupInfo.java
+6
-3
snode/src/main/java/org/apache/rocketmq/snode/client/ConsumerManager.java
...ava/org/apache/rocketmq/snode/client/ConsumerManager.java
+60
-35
snode/src/main/java/org/apache/rocketmq/snode/processor/HeartbeatProcessor.java
...g/apache/rocketmq/snode/processor/HeartbeatProcessor.java
+1
-1
snode/src/main/java/org/apache/rocketmq/snode/service/impl/PushServiceImpl.java
...g/apache/rocketmq/snode/service/impl/PushServiceImpl.java
+18
-10
未找到文件。
snode/src/main/java/org/apache/rocketmq/snode/client/ClientHousekeepingService.java
浏览文件 @
2fb8b5f2
...
...
@@ -16,7 +16,6 @@
*/
package
org.apache.rocketmq.snode.client
;
import
io.netty.channel.Channel
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -27,8 +26,9 @@ import org.apache.rocketmq.logging.InternalLoggerFactory;
import
org.apache.rocketmq.remoting.ChannelEventListener
;
import
org.apache.rocketmq.remoting.RemotingChannel
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
import
org.apache.rocketmq.remoting.netty.NettyChannelImpl
;
/**
* TODO Refactor housekeeping service
*/
public
class
ClientHousekeepingService
implements
ChannelEventListener
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
BROKER_LOGGER_NAME
);
private
final
ProducerManager
producerManager
;
...
...
@@ -74,7 +74,7 @@ public class ClientHousekeepingService implements ChannelEventListener {
public
void
onChannelClose
(
String
remoteAddr
,
RemotingChannel
remotingChannel
)
{
log
.
info
(
"Remoting channel closed: {}"
,
RemotingHelper
.
parseChannelRemoteAddr
(
remotingChannel
.
remoteAddress
()));
this
.
producerManager
.
doChannelCloseEvent
(
remoteAddr
,
remotingChannel
);
this
.
produc
erManager
.
doChannelCloseEvent
(
remoteAddr
,
remotingChannel
);
this
.
consum
erManager
.
doChannelCloseEvent
(
remoteAddr
,
remotingChannel
);
}
@Override
...
...
snode/src/main/java/org/apache/rocketmq/snode/client/ConsumerGroupInfo.java
浏览文件 @
2fb8b5f2
...
...
@@ -37,8 +37,8 @@ public class ConsumerGroupInfo {
private
final
String
groupName
;
private
final
ConcurrentMap
<
String
/* Topic */
,
SubscriptionData
>
subscriptionTable
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentMap
<
RemotingChannel
,
ClientChannelInfo
>
channelInfoTable
=
new
ConcurrentHashMap
<>(
16
);
private
final
ConcurrentMap
<
RemotingChannel
,
ClientChannelInfo
>
channelInfoTable
=
new
ConcurrentHashMap
<>(
16
);
private
ConcurrentHashMap
<
RemotingChannel
,
Set
<
SubscriptionData
>>
channelSubscriptionTable
=
new
ConcurrentHashMap
<>(
2048
);
private
volatile
ConsumeType
consumeType
;
...
...
@@ -129,7 +129,10 @@ public class ConsumerGroupInfo {
}
public
void
removeChannelSubscription
(
final
RemotingChannel
remotingChannel
)
{
this
.
channelSubscriptionTable
.
remove
(
remotingChannel
);
Set
<
SubscriptionData
>
subscriptionDataSet
=
this
.
channelSubscriptionTable
.
remove
(
remotingChannel
);
if
(
subscriptionDataSet
!=
null
)
{
log
.
debug
(
"Unregister a push session[{}] from consumerGroupInfo {}"
,
this
.
groupName
,
subscriptionDataSet
);
}
}
public
boolean
updateChannel
(
final
ClientChannelInfo
infoNew
,
ConsumeType
consumeType
,
...
...
snode/src/main/java/org/apache/rocketmq/snode/client/ConsumerManager.java
浏览文件 @
2fb8b5f2
...
...
@@ -32,15 +32,19 @@ import org.apache.rocketmq.logging.InternalLoggerFactory;
import
org.apache.rocketmq.remoting.RemotingChannel
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
/**
* TODO Refactor this manager
*/
public
class
ConsumerManager
{
private
static
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
BROKER_LOGGER_NAME
);
private
static
final
long
CHANNEL_EXPIRED_TIMEOUT
=
1000
*
120
;
private
final
ConcurrentMap
<
String
/* Group */
,
ConsumerGroupInfo
>
consumerTable
=
new
ConcurrentHashMap
<>(
1024
);
private
final
ConcurrentMap
<
String
/*Group*/
,
ConsumerGroupInfo
>
consumerTable
=
new
ConcurrentHashMap
<>(
1024
);
private
final
ConcurrentHashMap
<
String
/*Topic*/
,
ConcurrentHashMap
<
Integer
/*QueueId*/
,
ConcurrentHashMap
<
String
/*ConsumerGroup*/
,
ClientChannelInfo
>>>
topicConsumerTable
=
new
ConcurrentHashMap
<>(
2048
);
private
final
ConsumerIdsChangeListener
consumerIdsChangeListener
;
private
final
ConcurrentHashMap
<
String
/*Topic*/
,
ConcurrentHashMap
<
Integer
/*QueueId*/
,
ClientChannelInfo
>>
topicConsumerTable
=
new
ConcurrentHashMap
<>(
2048
)
;
private
static
final
long
CHANNEL_EXPIRED_TIMEOUT
=
1000
*
120
;
public
ConsumerManager
(
final
ConsumerIdsChangeListener
consumerIdsChangeListener
)
{
this
.
consumerIdsChangeListener
=
consumerIdsChangeListener
;
...
...
@@ -68,10 +72,10 @@ public class ConsumerManager {
return
0
;
}
private
void
removePushSession
(
final
ConsumerGroupInfo
info
,
final
RemotingChannel
channel
)
{
private
void
clearPushSession
(
final
String
consumerGroup
,
final
ConsumerGroupInfo
info
,
final
RemotingChannel
channel
)
{
Set
<
SubscriptionData
>
subscriptionDataSet
=
info
.
getSubscriotionDataSet
(
channel
);
removeConsumerTopicTable
(
subscriptionDataSet
,
channel
);
removeConsumerTopicTable
(
consumerGroup
,
subscriptionDataSet
,
channel
);
}
public
void
doChannelCloseEvent
(
final
String
remoteAddr
,
final
RemotingChannel
channel
)
{
...
...
@@ -79,7 +83,7 @@ public class ConsumerManager {
while
(
it
.
hasNext
())
{
Entry
<
String
,
ConsumerGroupInfo
>
next
=
it
.
next
();
ConsumerGroupInfo
info
=
next
.
getValue
();
removePushSession
(
info
,
channel
);
clearPushSession
(
info
.
getGroupName
(),
info
,
channel
);
boolean
removed
=
info
.
doChannelCloseEvent
(
remoteAddr
,
channel
);
if
(
removed
)
{
if
(
info
.
getChannelInfoTable
().
isEmpty
())
{
...
...
@@ -105,9 +109,9 @@ public class ConsumerManager {
consumerGroupInfo
=
prev
!=
null
?
prev
:
tmp
;
}
boolean
r1
=
consume
rGroupInfo
.
updateChannel
(
clientChannelInfo
,
consumeType
,
messageModel
,
consumeFromWhere
);
boolean
r1
=
consumerGroupInfo
.
updateChannel
(
clientChannelInfo
,
consumeType
,
messageModel
,
consume
FromWhere
);
boolean
r2
=
consumerGroupInfo
.
updateSubscription
(
subList
);
consumerGroupInfo
.
updateChannelSubscription
(
clientChannelInfo
,
subList
);
...
...
@@ -128,7 +132,7 @@ public class ConsumerManager {
if
(
null
!=
consumerGroupInfo
)
{
consumerGroupInfo
.
unregisterChannel
(
clientChannelInfo
);
consumerGroupInfo
.
removeChannelSubscription
(
clientChannelInfo
.
getChannel
());
removePushSession
(
consumerGroupInfo
,
clientChannelInfo
.
getChannel
());
clearPushSession
(
group
,
consumerGroupInfo
,
clientChannelInfo
.
getChannel
());
if
(
consumerGroupInfo
.
getChannelInfoTable
().
isEmpty
())
{
ConsumerGroupInfo
remove
=
this
.
consumerTable
.
remove
(
group
);
if
(
remove
!=
null
)
{
...
...
@@ -189,46 +193,67 @@ public class ConsumerManager {
return
groups
;
}
public
void
updateTopicConsumerTable
(
Set
<
SubscriptionData
>
subscriptionDataSet
,
public
void
registerPushSession
(
String
consumerGroup
,
Set
<
SubscriptionData
>
subscriptionDataSet
,
ClientChannelInfo
clientChannelInfo
)
{
for
(
SubscriptionData
subscriptionData
:
subscriptionDataSet
)
{
String
topic
=
subscriptionData
.
getTopic
();
for
(
Integer
queueId
:
subscriptionData
.
getQueueIdSet
())
{
ConcurrentHashMap
<
Integer
,
ClientChannelInfo
>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
if
(
clientChannelInfoMap
==
null
)
{
clientChannelInfoMap
=
new
ConcurrentHashMap
<>();
ConcurrentHashMap
prev
=
this
.
topicConsumerTable
.
putIfAbsent
(
topic
,
clientChannelInfoMap
);
if
(
prev
!=
null
)
{
clientChannelInfoMap
=
prev
;
if
(
clientChannelInfo
!=
null
)
{
for
(
SubscriptionData
subscriptionData
:
subscriptionDataSet
)
{
String
topic
=
subscriptionData
.
getTopic
();
for
(
Integer
queueId
:
subscriptionData
.
getQueueIdSet
())
{
ConcurrentHashMap
<
Integer
,
ConcurrentHashMap
<
String
,
ClientChannelInfo
>>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
if
(
clientChannelInfoMap
==
null
)
{
clientChannelInfoMap
=
new
ConcurrentHashMap
<>();
ConcurrentHashMap
prev
=
this
.
topicConsumerTable
.
putIfAbsent
(
topic
,
clientChannelInfoMap
);
if
(
prev
!=
null
)
{
clientChannelInfoMap
=
prev
;
}
}
log
.
info
(
"Register push for consumer group: {} topic: {}, queueId: {}"
,
consumerGroup
,
topic
,
queueId
);
ConcurrentHashMap
<
String
,
ClientChannelInfo
>
consumerGroupChannelTable
=
clientChannelInfoMap
.
get
(
queueId
);
if
(
consumerGroupChannelTable
==
null
)
{
consumerGroupChannelTable
=
new
ConcurrentHashMap
<>();
ConcurrentHashMap
<
String
,
ClientChannelInfo
>
preMap
=
clientChannelInfoMap
.
putIfAbsent
(
queueId
,
consumerGroupChannelTable
);
if
(
preMap
!=
null
)
{
consumerGroupChannelTable
=
preMap
;
}
}
consumerGroupChannelTable
.
putIfAbsent
(
consumerGroup
,
clientChannelInfo
);
clientChannelInfoMap
.
put
(
queueId
,
consumerGroupChannelTable
);
}
clientChannelInfoMap
.
put
(
queueId
,
clientChannelInfo
);
}
}
}
public
C
lientChannelInfo
getClientInfoTable
(
String
topic
,
Integer
queueId
)
{
ConcurrentHashMap
<
Integer
,
C
lientChannelInfo
>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
public
C
oncurrentHashMap
getClientInfoTable
(
String
topic
,
Integer
queueId
)
{
ConcurrentHashMap
<
Integer
,
C
oncurrentHashMap
<
String
,
ClientChannelInfo
>
>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
if
(
clientChannelInfoMap
!=
null
)
{
return
clientChannelInfoMap
.
get
(
queueId
);
}
return
null
;
}
public
void
removeConsumerTopicTable
(
Set
<
SubscriptionData
>
subscriptionDataSet
,
public
void
removeConsumerTopicTable
(
S
tring
consumerGroup
,
S
et
<
SubscriptionData
>
subscriptionDataSet
,
RemotingChannel
remotingChannel
)
{
for
(
SubscriptionData
subscriptionData
:
subscriptionDataSet
)
{
String
topic
=
subscriptionData
.
getTopic
();
for
(
Integer
queueId
:
subscriptionData
.
getQueueIdSet
())
{
ConcurrentHashMap
<
Integer
,
ClientChannelInfo
>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
if
(
clientChannelInfoMap
!=
null
)
{
ClientChannelInfo
old
=
clientChannelInfoMap
.
get
(
queueId
);
if
(
old
!=
null
&&
old
.
getChannel
()
==
remotingChannel
)
{
clientChannelInfoMap
.
remove
(
queueId
,
old
);
if
(
subscriptionDataSet
!=
null
)
{
for
(
SubscriptionData
subscriptionData
:
subscriptionDataSet
)
{
String
topic
=
subscriptionData
.
getTopic
();
for
(
Integer
queueId
:
subscriptionData
.
getQueueIdSet
())
{
ConcurrentHashMap
<
Integer
,
ConcurrentHashMap
<
String
,
ClientChannelInfo
>>
clientChannelInfoMap
=
this
.
topicConsumerTable
.
get
(
topic
);
if
(
clientChannelInfoMap
!=
null
)
{
ConcurrentHashMap
<
String
,
ClientChannelInfo
>
queueConsumerGroupMap
=
clientChannelInfoMap
.
get
(
queueId
);
if
(
queueConsumerGroupMap
!=
null
)
{
ClientChannelInfo
clientChannelInfo
=
queueConsumerGroupMap
.
get
(
consumerGroup
);
if
(
clientChannelInfo
.
getChannel
().
equals
(
remotingChannel
))
{
log
.
info
(
"Remove push topic: {}, queueId: {}, consumerGroup:{} session"
,
topic
,
queueId
,
consumerGroup
);
queueConsumerGroupMap
.
remove
(
consumerGroup
,
clientChannelInfo
);
}
}
if
(
clientChannelInfoMap
.
isEmpty
())
{
log
.
info
(
"All consumer offline, so remove this map"
);
this
.
topicConsumerTable
.
remove
(
topic
,
clientChannelInfoMap
);
}
}
}
}
}
}
}
snode/src/main/java/org/apache/rocketmq/snode/processor/HeartbeatProcessor.java
浏览文件 @
2fb8b5f2
...
...
@@ -101,7 +101,7 @@ public class HeartbeatProcessor implements RequestProcessor {
}
if
(
data
.
isRealPushEnable
())
{
this
.
snodeController
.
getConsumerManager
().
updateTopicConsumerTable
(
data
.
getSubscriptionDataSet
(),
clientChannelInfo
);
this
.
snodeController
.
getConsumerManager
().
registerPushSession
(
data
.
getGroupName
(),
data
.
getSubscriptionDataSet
(),
clientChannelInfo
);
}
}
}
...
...
snode/src/main/java/org/apache/rocketmq/snode/service/impl/PushServiceImpl.java
浏览文件 @
2fb8b5f2
...
...
@@ -16,7 +16,11 @@
*/
package
org.apache.rocketmq.snode.service.impl
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -76,15 +80,19 @@ public class PushServiceImpl implements PushService {
pushMessageHeader
.
setQueueOffset
(
sendMessageResponseHeader
.
getQueueOffset
());
pushMessageHeader
.
setTopic
(
topic
);
pushMessageHeader
.
setQueueId
(
queueId
);
RemotingCommand
pushMessage
=
RemotingCommand
.
createRe
sponseCommand
(
PushMessageHeader
.
class
);
RemotingCommand
pushMessage
=
RemotingCommand
.
createRe
questCommand
(
RequestCode
.
SNODE_PUSH_MESSAGE
,
pushMessageHeader
);
pushMessage
.
setBody
(
message
);
pushMessage
.
setCustomHeader
(
pushMessageHeader
);
pushMessage
.
setCode
(
RequestCode
.
SNODE_PUSH_MESSAGE
);
ClientChannelInfo
clientChannelInfo
=
snodeController
.
getConsumerManager
().
getClientInfoTable
(
topic
,
queueId
);
if
(
clientChannelInfo
!=
null
)
{
log
.
warn
(
"Push message to topic: {} queueId: {}, message:{}"
,
topic
,
queueId
,
pushMessage
);
RemotingChannel
remotingChannel
=
clientChannelInfo
.
getChannel
();
snodeController
.
getSnodeServer
().
push
(
remotingChannel
,
pushMessage
,
SnodeConstant
.
defaultTimeoutMills
);
ConcurrentHashMap
consumerGroupTable
=
snodeController
.
getConsumerManager
().
getClientInfoTable
(
topic
,
queueId
);
if
(
consumerGroupTable
!=
null
)
{
Iterator
<
Map
.
Entry
<
String
,
ClientChannelInfo
>>
itChannel
=
consumerGroupTable
.
entrySet
().
iterator
();
while
(
itChannel
.
hasNext
())
{
Entry
<
String
,
ClientChannelInfo
>
clientChannelInfoEntry
=
itChannel
.
next
();
RemotingChannel
remotingChannel
=
clientChannelInfoEntry
.
getValue
().
getChannel
();
if
(
remotingChannel
.
isWritable
())
{
log
.
warn
(
"Push message to topic: {} queueId: {} consumer group:{}, message:{}"
,
topic
,
queueId
,
clientChannelInfoEntry
.
getKey
(),
pushMessage
);
snodeController
.
getSnodeServer
().
push
(
remotingChannel
,
pushMessage
,
SnodeConstant
.
defaultTimeoutMills
);
}
}
}
else
{
log
.
warn
(
"Get client info to topic: {} queueId: {} is null"
,
topic
,
queueId
);
}
...
...
@@ -115,8 +123,8 @@ public class PushServiceImpl implements PushService {
@Override
public
void
pushMessage
(
final
String
topic
,
final
Integer
queueId
,
final
byte
[]
message
,
final
RemotingCommand
response
)
{
C
lientChannelInfo
clientChannelInfo
=
this
.
snodeController
.
getConsumerManager
().
getClientInfoTable
(
topic
,
queueId
);
if
(
clientChannelInfo
!=
null
)
{
C
oncurrentHashMap
<
String
,
ClientChannelInfo
>
clientChannelInfoTable
=
this
.
snodeController
.
getConsumerManager
().
getClientInfoTable
(
topic
,
queueId
);
if
(
clientChannelInfo
Table
!=
null
)
{
PushTask
pushTask
=
new
PushTask
(
topic
,
queueId
,
message
,
response
);
pushMessageExecutorService
.
submit
(
pushTask
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录