Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
2669a5c4
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看板
提交
2669a5c4
编写于
2月 23, 2019
作者:
S
ShannonDing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support origin 4.x
上级
510bb34f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
189 addition
and
88 deletion
+189
-88
client/src/main/java/org/apache/rocketmq/client/ClientConfig.java
...rc/main/java/org/apache/rocketmq/client/ClientConfig.java
+12
-1
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQRealPushConsumer.java
...e/rocketmq/client/consumer/DefaultMQRealPushConsumer.java
+3
-0
client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java
...cketmq/client/consumer/store/RemoteBrokerOffsetStore.java
+29
-15
client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
...java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
+1
-1
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
.../apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
+19
-8
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java
...apache/rocketmq/client/impl/factory/MQClientInstance.java
+98
-48
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
.../rocketmq/client/impl/producer/DefaultMQProducerImpl.java
+27
-15
未找到文件。
client/src/main/java/org/apache/rocketmq/client/ClientConfig.java
浏览文件 @
2669a5c4
...
@@ -50,6 +50,7 @@ public class ClientConfig {
...
@@ -50,6 +50,7 @@ public class ClientConfig {
private
boolean
useTLS
=
TlsSystemConfig
.
tlsEnable
;
private
boolean
useTLS
=
TlsSystemConfig
.
tlsEnable
;
private
LanguageCode
language
=
LanguageCode
.
JAVA
;
private
LanguageCode
language
=
LanguageCode
.
JAVA
;
private
boolean
realPush
=
false
;
public
String
buildMQClientId
()
{
public
String
buildMQClientId
()
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
...
@@ -100,6 +101,7 @@ public class ClientConfig {
...
@@ -100,6 +101,7 @@ public class ClientConfig {
this
.
vipChannelEnabled
=
cc
.
vipChannelEnabled
;
this
.
vipChannelEnabled
=
cc
.
vipChannelEnabled
;
this
.
useTLS
=
cc
.
useTLS
;
this
.
useTLS
=
cc
.
useTLS
;
this
.
language
=
cc
.
language
;
this
.
language
=
cc
.
language
;
this
.
realPush
=
cc
.
realPush
;
}
}
public
ClientConfig
cloneClientConfig
()
{
public
ClientConfig
cloneClientConfig
()
{
...
@@ -116,6 +118,7 @@ public class ClientConfig {
...
@@ -116,6 +118,7 @@ public class ClientConfig {
cc
.
vipChannelEnabled
=
vipChannelEnabled
;
cc
.
vipChannelEnabled
=
vipChannelEnabled
;
cc
.
useTLS
=
useTLS
;
cc
.
useTLS
=
useTLS
;
cc
.
language
=
language
;
cc
.
language
=
language
;
cc
.
realPush
=
realPush
;
return
cc
;
return
cc
;
}
}
...
@@ -199,12 +202,20 @@ public class ClientConfig {
...
@@ -199,12 +202,20 @@ public class ClientConfig {
this
.
language
=
language
;
this
.
language
=
language
;
}
}
public
boolean
isRealPush
()
{
return
realPush
;
}
public
void
setRealPush
(
boolean
realPush
)
{
this
.
realPush
=
realPush
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"ClientConfig [namesrvAddr="
+
namesrvAddr
+
", clientIP="
+
clientIP
+
", instanceName="
+
instanceName
return
"ClientConfig [namesrvAddr="
+
namesrvAddr
+
", clientIP="
+
clientIP
+
", instanceName="
+
instanceName
+
", clientCallbackExecutorThreads="
+
clientCallbackExecutorThreads
+
", pollNameServerInterval="
+
pollNameServerInterval
+
", clientCallbackExecutorThreads="
+
clientCallbackExecutorThreads
+
", pollNameServerInterval="
+
pollNameServerInterval
+
", heartbeatBrokerInterval="
+
heartbeatBrokerInterval
+
", persistConsumerOffsetInterval="
+
", heartbeatBrokerInterval="
+
heartbeatBrokerInterval
+
", persistConsumerOffsetInterval="
+
persistConsumerOffsetInterval
+
", unitMode="
+
unitMode
+
", unitName="
+
unitName
+
", vipChannelEnabled="
+
persistConsumerOffsetInterval
+
", unitMode="
+
unitMode
+
", unitName="
+
unitName
+
", vipChannelEnabled="
+
vipChannelEnabled
+
", useTLS="
+
useTLS
+
", language="
+
language
.
name
()
+
"]"
;
+
vipChannelEnabled
+
", useTLS="
+
useTLS
+
", language="
+
language
.
name
()
+
"
, realPush="
+
realPush
+
"
]"
;
}
}
}
}
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQRealPushConsumer.java
浏览文件 @
2669a5c4
...
@@ -273,6 +273,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
...
@@ -273,6 +273,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
public
DefaultMQRealPushConsumer
(
final
String
consumerGroup
,
RPCHook
rpcHook
,
public
DefaultMQRealPushConsumer
(
final
String
consumerGroup
,
RPCHook
rpcHook
,
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
)
{
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
)
{
this
.
consumerGroup
=
consumerGroup
;
this
.
consumerGroup
=
consumerGroup
;
this
.
setRealPush
(
true
);
this
.
allocateMessageQueueStrategy
=
allocateMessageQueueStrategy
;
this
.
allocateMessageQueueStrategy
=
allocateMessageQueueStrategy
;
defaultMQPushConsumerImpl
=
new
DefaultMQRealPushConsumerImpl
(
this
,
rpcHook
);
defaultMQPushConsumerImpl
=
new
DefaultMQRealPushConsumerImpl
(
this
,
rpcHook
);
}
}
...
@@ -287,6 +288,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
...
@@ -287,6 +288,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
public
DefaultMQRealPushConsumer
(
final
String
consumerGroup
,
RPCHook
rpcHook
,
public
DefaultMQRealPushConsumer
(
final
String
consumerGroup
,
RPCHook
rpcHook
,
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
,
boolean
realPushModel
)
{
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
,
boolean
realPushModel
)
{
this
.
consumerGroup
=
consumerGroup
;
this
.
consumerGroup
=
consumerGroup
;
this
.
setRealPush
(
true
);
if
(
allocateMessageQueueStrategy
==
null
)
{
if
(
allocateMessageQueueStrategy
==
null
)
{
this
.
allocateMessageQueueStrategy
=
new
AllocateMessageQueueAveragely
();
this
.
allocateMessageQueueStrategy
=
new
AllocateMessageQueueAveragely
();
}
else
{
}
else
{
...
@@ -310,6 +312,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
...
@@ -310,6 +312,7 @@ public class DefaultMQRealPushConsumer extends ClientConfig implements MQRealPus
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
,
boolean
enableMsgTrace
,
AllocateMessageQueueStrategy
allocateMessageQueueStrategy
,
boolean
enableMsgTrace
,
final
String
customizedTraceTopic
)
{
final
String
customizedTraceTopic
)
{
this
.
consumerGroup
=
consumerGroup
;
this
.
consumerGroup
=
consumerGroup
;
this
.
setRealPush
(
true
);
this
.
allocateMessageQueueStrategy
=
allocateMessageQueueStrategy
;
this
.
allocateMessageQueueStrategy
=
allocateMessageQueueStrategy
;
defaultMQPushConsumerImpl
=
new
DefaultMQRealPushConsumerImpl
(
this
,
rpcHook
);
defaultMQPushConsumerImpl
=
new
DefaultMQRealPushConsumerImpl
(
this
,
rpcHook
);
if
(
enableMsgTrace
)
{
if
(
enableMsgTrace
)
{
...
...
client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java
浏览文件 @
2669a5c4
...
@@ -88,7 +88,12 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
...
@@ -88,7 +88,12 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
}
}
case
READ_FROM_STORE:
{
case
READ_FROM_STORE:
{
try
{
try
{
long
brokerOffset
=
this
.
fetchConsumeOffsetFromSnode
(
mq
);
long
brokerOffset
=
0L
;
if
(
this
.
mQClientFactory
.
getClientConfig
().
isRealPush
())
{
brokerOffset
=
this
.
fetchConsumeOffsetFromSnode
(
mq
);
}
else
{
brokerOffset
=
this
.
fetchConsumeOffsetFromBroker
(
mq
);
}
AtomicLong
offset
=
new
AtomicLong
(
brokerOffset
);
AtomicLong
offset
=
new
AtomicLong
(
brokerOffset
);
this
.
updateOffset
(
mq
,
offset
.
get
(),
false
);
this
.
updateOffset
(
mq
,
offset
.
get
(),
false
);
return
brokerOffset
;
return
brokerOffset
;
...
@@ -124,14 +129,18 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
...
@@ -124,14 +129,18 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
if
(
offset
!=
null
)
{
if
(
offset
!=
null
)
{
if
(
mqs
.
contains
(
mq
))
{
if
(
mqs
.
contains
(
mq
))
{
try
{
try
{
this
.
updateConsumeOffsetToSnode
(
mq
,
offset
.
get
());
if
(
this
.
mQClientFactory
.
getClientConfig
().
isRealPush
())
{
log
.
info
(
"[persistAll] Group: {} ClientId: {} updateConsumeOffsetToSnode {} {}"
,
this
.
updateConsumeOffsetToSnode
(
mq
,
offset
.
get
());
}
else
{
this
.
updateConsumeOffsetToBroker
(
mq
,
offset
.
get
());
}
log
.
info
(
"[persistAll] Group: {} ClientId: {} updateConsumeOffsetToBroker {} {}"
,
this
.
groupName
,
this
.
groupName
,
this
.
mQClientFactory
.
getClientId
(),
this
.
mQClientFactory
.
getClientId
(),
mq
,
mq
,
offset
.
get
());
offset
.
get
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"updateConsumeOffsetTo
Snode
exception, "
+
mq
.
toString
(),
e
);
log
.
error
(
"updateConsumeOffsetTo
Broker
exception, "
+
mq
.
toString
(),
e
);
}
}
}
else
{
}
else
{
unusedMQ
.
add
(
mq
);
unusedMQ
.
add
(
mq
);
...
@@ -153,14 +162,18 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
...
@@ -153,14 +162,18 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
AtomicLong
offset
=
this
.
offsetTable
.
get
(
mq
);
AtomicLong
offset
=
this
.
offsetTable
.
get
(
mq
);
if
(
offset
!=
null
)
{
if
(
offset
!=
null
)
{
try
{
try
{
this
.
updateConsumeOffsetToSnode
(
mq
,
offset
.
get
());
if
(
this
.
mQClientFactory
.
getClientConfig
().
isRealPush
())
{
log
.
info
(
"[persist] Group: {} ClientId: {} updateConsumeOffsetToSnode {} {}"
,
this
.
updateConsumeOffsetToSnode
(
mq
,
offset
.
get
());
}
else
{
this
.
updateConsumeOffsetToBroker
(
mq
,
offset
.
get
());
}
log
.
info
(
"[persist] Group: {} ClientId: {} updateConsumeOffsetTobroker {} {}"
,
this
.
groupName
,
this
.
groupName
,
this
.
mQClientFactory
.
getClientId
(),
this
.
mQClientFactory
.
getClientId
(),
mq
,
mq
,
offset
.
get
());
offset
.
get
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"updateConsumeOffsetTo
Snode
exception, "
+
mq
.
toString
(),
e
);
log
.
error
(
"updateConsumeOffsetTo
broker
exception, "
+
mq
.
toString
(),
e
);
}
}
}
}
}
}
...
@@ -288,22 +301,23 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
...
@@ -288,22 +301,23 @@ public class RemoteBrokerOffsetStore implements OffsetStore {
*/
*/
private
long
fetchConsumeOffsetFromBroker
(
MessageQueue
mq
)
throws
RemotingException
,
MQBrokerException
,
private
long
fetchConsumeOffsetFromBroker
(
MessageQueue
mq
)
throws
RemotingException
,
MQBrokerException
,
InterruptedException
,
MQClientException
{
InterruptedException
,
MQClientException
{
String
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
FindBrokerResult
findBrokerResult
=
this
.
mQClientFactory
.
findBrokerAddressInAdmin
(
mq
.
getBrokerName
());
if
(
null
==
snodeAddr
)
{
if
(
null
==
findBrokerResult
)
{
this
.
mQClientFactory
.
updateSnodeInfoFromNameServer
();
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
this
.
mQClientFactory
.
updateTopicRouteInfoFromNameServer
(
mq
.
getTopic
());
findBrokerResult
=
this
.
mQClientFactory
.
findBrokerAddressInAdmin
(
mq
.
getBrokerName
());
}
}
if
(
snodeAddr
!=
null
)
{
if
(
findBrokerResult
!=
null
)
{
QueryConsumerOffsetRequestHeader
requestHeader
=
new
QueryConsumerOffsetRequestHeader
();
QueryConsumerOffsetRequestHeader
requestHeader
=
new
QueryConsumerOffsetRequestHeader
();
requestHeader
.
setTopic
(
mq
.
getTopic
());
requestHeader
.
setTopic
(
mq
.
getTopic
());
requestHeader
.
setConsumerGroup
(
this
.
groupName
);
requestHeader
.
setConsumerGroup
(
this
.
groupName
);
requestHeader
.
setQueueId
(
mq
.
getQueueId
());
requestHeader
.
setQueueId
(
mq
.
getQueueId
());
requestHeader
.
setEnodeName
(
mq
.
getBrokerName
());
return
this
.
mQClientFactory
.
getMQClientAPIImpl
().
queryConsumerOffset
(
return
this
.
mQClientFactory
.
getMQClientAPIImpl
().
queryConsumerOffset
(
snodeAddr
,
requestHeader
,
1000
*
5
);
findBrokerResult
.
getBrokerAddr
()
,
requestHeader
,
1000
*
5
);
}
else
{
}
else
{
throw
new
MQClientException
(
"
Get Offset from broker["
+
mq
.
getBrokerName
()
+
"] failed, Snode is
not exist"
,
null
);
throw
new
MQClientException
(
"
The broker["
+
mq
.
getBrokerName
()
+
"]
not exist"
,
null
);
}
}
}
}
}
}
client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
浏览文件 @
2669a5c4
...
@@ -567,7 +567,7 @@ public class MQClientAPIImpl {
...
@@ -567,7 +567,7 @@ public class MQClientAPIImpl {
final
CommunicationMode
communicationMode
,
final
CommunicationMode
communicationMode
,
final
PullCallback
pullCallback
final
PullCallback
pullCallback
)
throws
RemotingException
,
MQSnodeException
,
InterruptedException
{
)
throws
RemotingException
,
MQSnodeException
,
InterruptedException
{
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
RequestCode
.
SNODE_
PULL_MESSAGE
,
requestHeader
);
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
RequestCode
.
PULL_MESSAGE
,
requestHeader
);
switch
(
communicationMode
)
{
switch
(
communicationMode
)
{
case
ONEWAY:
case
ONEWAY:
assert
false
;
assert
false
;
...
...
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
浏览文件 @
2669a5c4
...
@@ -177,13 +177,24 @@ public class PullAPIWrapper {
...
@@ -177,13 +177,24 @@ public class PullAPIWrapper {
if
(
findBrokerResult
.
isSlave
())
{
if
(
findBrokerResult
.
isSlave
())
{
sysFlagInner
=
PullSysFlag
.
clearCommitOffsetFlag
(
sysFlagInner
);
sysFlagInner
=
PullSysFlag
.
clearCommitOffsetFlag
(
sysFlagInner
);
}
}
String
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
String
addr
=
null
;
if
(
snodeAddr
==
null
)
{
if
(
this
.
mQClientFactory
.
getClientConfig
().
isRealPush
())
{
this
.
mQClientFactory
.
updateSnodeInfoFromNameServer
();
addr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
if
(
addr
==
null
)
{
}
this
.
mQClientFactory
.
updateSnodeInfoFromNameServer
();
if
(
snodeAddr
==
null
)
{
addr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
throw
new
MQClientException
(
"The snode addr is null."
,
null
);
}
if
(
addr
==
null
)
{
throw
new
MQClientException
(
"The snode addr is null."
,
null
);
}
}
else
{
addr
=
findBrokerResult
.
getBrokerAddr
();
if
(
PullSysFlag
.
hasClassFilterFlag
(
sysFlagInner
))
{
addr
=
computPullFromWhichFilterServer
(
mq
.
getTopic
(),
addr
);
}
if
(
addr
==
null
)
{
throw
new
MQClientException
(
"The broker addr is null."
,
null
);
}
}
}
PullMessageRequestHeader
requestHeader
=
new
PullMessageRequestHeader
();
PullMessageRequestHeader
requestHeader
=
new
PullMessageRequestHeader
();
requestHeader
.
setConsumerGroup
(
this
.
consumerGroup
);
requestHeader
.
setConsumerGroup
(
this
.
consumerGroup
);
...
@@ -200,7 +211,7 @@ public class PullAPIWrapper {
...
@@ -200,7 +211,7 @@ public class PullAPIWrapper {
requestHeader
.
setEnodeName
(
mq
.
getBrokerName
());
requestHeader
.
setEnodeName
(
mq
.
getBrokerName
());
PullResult
pullResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
pullMessage
(
PullResult
pullResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
pullMessage
(
snodeA
ddr
,
a
ddr
,
requestHeader
,
requestHeader
,
timeoutMillis
,
timeoutMillis
,
communicationMode
,
communicationMode
,
...
...
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java
浏览文件 @
2669a5c4
...
@@ -38,6 +38,7 @@ import java.util.concurrent.locks.Lock;
...
@@ -38,6 +38,7 @@ import java.util.concurrent.locks.Lock;
import
java.util.concurrent.locks.ReentrantLock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
org.apache.rocketmq.client.admin.MQAdminExtInner
;
import
org.apache.rocketmq.client.admin.MQAdminExtInner
;
import
org.apache.rocketmq.client.common.ThreadLocalIndex
;
import
org.apache.rocketmq.client.common.ThreadLocalIndex
;
import
org.apache.rocketmq.client.exception.MQBrokerException
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.impl.ClientRemotingProcessor
;
import
org.apache.rocketmq.client.impl.ClientRemotingProcessor
;
import
org.apache.rocketmq.client.impl.FindBrokerResult
;
import
org.apache.rocketmq.client.impl.FindBrokerResult
;
...
@@ -80,6 +81,7 @@ import org.apache.rocketmq.common.protocol.route.TopicRouteData;
...
@@ -80,6 +81,7 @@ import org.apache.rocketmq.common.protocol.route.TopicRouteData;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.logging.InternalLogger
;
import
org.apache.rocketmq.remoting.ClientConfig
;
import
org.apache.rocketmq.remoting.ClientConfig
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
import
org.apache.rocketmq.remoting.common.RemotingHelper
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.interceptor.InterceptorGroup
;
import
org.apache.rocketmq.remoting.interceptor.InterceptorGroup
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
...
@@ -290,39 +292,44 @@ public class MQClientInstance {
...
@@ -290,39 +292,44 @@ public class MQClientInstance {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"ScheduledTask updateTopicRouteInfoFromNameServer exception"
,
e
);
log
.
error
(
"ScheduledTask updateTopicRouteInfoFromNameServer exception"
,
e
);
}
}
try
{
MQClientInstance
.
this
.
updateSnodeInfoFromNameServer
();
if
(
MQClientInstance
.
this
.
clientConfig
.
isRealPush
())
{
}
catch
(
Exception
e
)
{
try
{
log
.
error
(
"ScheduledTask updateSnodeInfoFromNameServer exception"
,
e
);
MQClientInstance
.
this
.
updateSnodeInfoFromNameServer
();
}
catch
(
Exception
e
)
{
log
.
error
(
"ScheduledTask updateSnodeInfoFromNameServer exception"
,
e
);
}
}
}
}
}
},
10
,
this
.
clientConfig
.
getPollNameServerInterval
(),
TimeUnit
.
MILLISECONDS
);
},
10
,
this
.
clientConfig
.
getPollNameServerInterval
(),
TimeUnit
.
MILLISECONDS
);
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
if
(
this
.
clientConfig
.
isRealPush
())
{
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
//MQClientInstance.this.cleanOfflineSnode();
//MQClientInstance.this.cleanOfflineSnode();
MQClientInstance
.
this
.
sendHeartbeatToAllSnodeWithLock
();
MQClientInstance
.
this
.
sendHeartbeatToAllSnodeWithLock
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"ScheduledTask updateSnodeInfoFromNameServer exception"
,
e
);
log
.
error
(
"ScheduledTask updateSnodeInfoFromNameServer exception"
,
e
);
}
}
}
}
}
,
1000
,
this
.
clientConfig
.
getHeartbeatBrokerInterval
(),
TimeUnit
.
MILLISECONDS
);
}
,
1000
,
this
.
clientConfig
.
getHeartbeatBrokerInterval
(),
TimeUnit
.
MILLISECONDS
);
}
else
{
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
// this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
//
@Override
// @Override
public
void
run
()
{
// public void run()
{
try
{
// try {
MQClientInstance
.
this
.
cleanOfflineBroker
();
// MQClientInstance.this.cleanOfflineBroker
();
MQClientInstance
.
this
.
sendHeartbeatToAllBrokerWithLock
();
// MQClientInstance.this.sendHeartbeatToAllBrokerWithLock();
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"ScheduledTask sendHeartbeatToAllBroker exception"
,
e
);
// log.error("ScheduledTask sendHeartbeatToAllBroker exception", e);
}
//
}
}
// }
},
1000
,
this
.
clientConfig
.
getHeartbeatBrokerInterval
(),
TimeUnit
.
MILLISECONDS
);
// }, 1000, this.clientConfig.getHeartbeatBrokerInterval(), TimeUnit.MILLISECONDS);
}
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
this
.
scheduledExecutorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
...
@@ -500,9 +507,12 @@ public class MQClientInstance {
...
@@ -500,9 +507,12 @@ public class MQClientInstance {
}
}
// may need to check one broker every cluster...
// may need to check one broker every cluster...
// assume that the configs of every broker in cluster are the the same.
// assume that the configs of every broker in cluster are the the same.
//String addr = findBrokerAddrByTopic(subscriptionData.getTopic());
String
addr
=
null
;
String
addr
=
findSnodeAddressInPublish
();
if
(
this
.
clientConfig
.
isRealPush
())
{
addr
=
findSnodeAddressInPublish
();
}
else
{
addr
=
findBrokerAddrByTopic
(
subscriptionData
.
getTopic
());
}
if
(
addr
!=
null
)
{
if
(
addr
!=
null
)
{
try
{
try
{
this
.
getMQClientAPIImpl
().
checkClientInBroker
(
this
.
getMQClientAPIImpl
().
checkClientInBroker
(
...
@@ -1016,20 +1026,47 @@ public class MQClientInstance {
...
@@ -1016,20 +1026,47 @@ public class MQClientInstance {
}
}
private
void
unregisterClient
(
final
String
producerGroup
,
final
String
consumerGroup
)
{
private
void
unregisterClient
(
final
String
producerGroup
,
final
String
consumerGroup
)
{
Iterator
<
Entry
<
String
,
String
>>
it
=
this
.
snodeAddrTable
.
entrySet
().
iterator
();
if
(!
this
.
clientConfig
.
isRealPush
())
{
while
(
it
.
hasNext
())
{
Iterator
<
Entry
<
String
,
HashMap
<
Long
,
String
>>>
it
=
this
.
brokerAddrTable
.
entrySet
().
iterator
();
Entry
<
String
,
String
>
entry
=
it
.
next
();
while
(
it
.
hasNext
())
{
String
snodeName
=
entry
.
getKey
();
Entry
<
String
,
HashMap
<
Long
,
String
>>
entry
=
it
.
next
();
String
snodeAddr
=
entry
.
getValue
();
String
brokerName
=
entry
.
getKey
();
if
(!
entry
.
getValue
().
isEmpty
())
{
HashMap
<
Long
,
String
>
oneTable
=
entry
.
getValue
();
try
{
this
.
mQClientAPIImpl
.
unregisterClient
(
snodeAddr
,
this
.
clientId
,
producerGroup
,
consumerGroup
,
3000
);
if
(
oneTable
!=
null
)
{
log
.
info
(
"unregister client[Producer: {} Consumer: {}] from snode[{} {}] success"
,
producerGroup
,
consumerGroup
,
snodeName
,
snodeAddr
);
for
(
Map
.
Entry
<
Long
,
String
>
entry1
:
oneTable
.
entrySet
())
{
}
catch
(
Exception
e
)
{
String
addr
=
entry1
.
getValue
();
log
.
error
(
"unregister client exception from snode: "
+
snodeAddr
,
e
);
if
(
addr
!=
null
)
{
try
{
this
.
mQClientAPIImpl
.
unregisterClient
(
addr
,
this
.
clientId
,
producerGroup
,
consumerGroup
,
3000
);
log
.
info
(
"unregister client[Producer: {} Consumer: {}] from broker[{} {} {}] success"
,
producerGroup
,
consumerGroup
,
brokerName
,
entry1
.
getKey
(),
addr
);
}
catch
(
RemotingException
e
)
{
log
.
error
(
"unregister client exception from broker: "
+
addr
,
e
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"unregister client exception from broker: "
+
addr
,
e
);
}
catch
(
MQBrokerException
e
)
{
log
.
error
(
"unregister client exception from broker: "
+
addr
,
e
);
}
}
}
}
}
}
}
}
else
{
Iterator
<
Entry
<
String
,
String
>>
it
=
this
.
snodeAddrTable
.
entrySet
().
iterator
();
while
(
it
.
hasNext
())
{
Entry
<
String
,
String
>
entry
=
it
.
next
();
String
snodeName
=
entry
.
getKey
();
String
snodeAddr
=
entry
.
getValue
();
if
(!
entry
.
getValue
().
isEmpty
())
{
try
{
this
.
mQClientAPIImpl
.
unregisterClient
(
snodeAddr
,
this
.
clientId
,
producerGroup
,
consumerGroup
,
3000
);
log
.
info
(
"unregister client[Producer: {} Consumer: {}] from snode[{} {}] success"
,
producerGroup
,
consumerGroup
,
snodeName
,
snodeAddr
);
}
catch
(
Exception
e
)
{
log
.
error
(
"unregister client exception from snode: "
+
snodeAddr
,
e
);
}
}
}
}
}
}
}
...
@@ -1192,17 +1229,26 @@ public class MQClientInstance {
...
@@ -1192,17 +1229,26 @@ public class MQClientInstance {
}
}
public
List
<
String
>
findConsumerIdList
(
final
String
topic
,
final
String
group
)
{
public
List
<
String
>
findConsumerIdList
(
final
String
topic
,
final
String
group
)
{
String
snodeAddr
=
this
.
findSnodeAddressInPublish
();
String
addr
=
null
;
if
(
null
==
snodeAddr
)
{
if
(
this
.
clientConfig
.
isRealPush
())
{
this
.
updateSnodeInfoFromNameServer
();
addr
=
this
.
findSnodeAddressInPublish
();
snodeAddr
=
this
.
findSnodeAddressInPublish
();
if
(
null
==
addr
)
{
this
.
updateSnodeInfoFromNameServer
();
addr
=
this
.
findSnodeAddressInPublish
();
}
}
else
{
addr
=
this
.
findBrokerAddrByTopic
(
topic
);
if
(
null
==
addr
)
{
this
.
updateTopicRouteInfoFromNameServer
(
topic
);
addr
=
this
.
findBrokerAddrByTopic
(
topic
);
}
}
}
if
(
null
!=
snodeA
ddr
)
{
if
(
null
!=
a
ddr
)
{
try
{
try
{
return
this
.
mQClientAPIImpl
.
getConsumerIdListByGroup
(
snodeA
ddr
,
group
,
3000
);
return
this
.
mQClientAPIImpl
.
getConsumerIdListByGroup
(
a
ddr
,
group
,
3000
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
warn
(
"getConsumerIdListByGroup exception, "
+
snodeA
ddr
+
" "
+
group
,
e
);
log
.
warn
(
"getConsumerIdListByGroup exception, "
+
a
ddr
+
" "
+
group
,
e
);
}
}
}
}
...
@@ -1395,4 +1441,8 @@ public class MQClientInstance {
...
@@ -1395,4 +1441,8 @@ public class MQClientInstance {
return
false
;
return
false
;
}
}
public
org
.
apache
.
rocketmq
.
client
.
ClientConfig
getClientConfig
()
{
return
clientConfig
;
}
}
}
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
浏览文件 @
2669a5c4
...
@@ -193,10 +193,12 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -193,10 +193,12 @@ public class DefaultMQProducerImpl implements MQProducerInner {
if
(
startFactory
)
{
if
(
startFactory
)
{
mQClientFactory
.
start
();
mQClientFactory
.
start
();
log
.
info
(
"Update Snode Info for the first time."
);
if
(
this
.
defaultMQProducer
.
isRealPush
())
{
mQClientFactory
.
updateSnodeInfoFromNameServer
();
log
.
info
(
"Update Snode Info for the first time."
);
log
.
info
(
"Send heartbeat to Snode Info for the first time."
);
mQClientFactory
.
updateSnodeInfoFromNameServer
();
mQClientFactory
.
sendHeartbeatToAllSnodeWithLock
();
log
.
info
(
"Send heartbeat to Snode Info for the first time."
);
mQClientFactory
.
sendHeartbeatToAllSnodeWithLock
();
}
}
}
log
.
info
(
"the producer [{}] start OK. sendMessageWithVIPChannel={}"
,
this
.
defaultMQProducer
.
getProducerGroup
(),
log
.
info
(
"the producer [{}] start OK. sendMessageWithVIPChannel={}"
,
this
.
defaultMQProducer
.
getProducerGroup
(),
...
@@ -214,7 +216,9 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -214,7 +216,9 @@ public class DefaultMQProducerImpl implements MQProducerInner {
break
;
break
;
}
}
// this.mQClientFactory.sendHeartbeatToAllBrokerWithLock();
if
(!
this
.
defaultMQProducer
.
isRealPush
())
{
this
.
mQClientFactory
.
sendHeartbeatToAllBrokerWithLock
();
}
}
}
private
void
checkConfig
()
throws
MQClientException
{
private
void
checkConfig
()
throws
MQClientException
{
...
@@ -690,14 +694,22 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -690,14 +694,22 @@ public class DefaultMQProducerImpl implements MQProducerInner {
final
TopicPublishInfo
topicPublishInfo
,
final
TopicPublishInfo
topicPublishInfo
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
long
beginStartTime
=
System
.
currentTimeMillis
();
long
beginStartTime
=
System
.
currentTimeMillis
();
String
addr
=
null
;
String
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
if
(
this
.
defaultMQProducer
.
isRealPush
())
{
if
(
null
==
snodeAddr
)
{
addr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
tryToFindSnodePublishInfo
();
if
(
null
==
addr
)
{
snodeAddr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
tryToFindSnodePublishInfo
();
addr
=
this
.
mQClientFactory
.
findSnodeAddressInPublish
();
}
}
else
{
addr
=
this
.
mQClientFactory
.
findBrokerAddressInPublish
(
mq
.
getBrokerName
());
if
(
null
==
addr
)
{
tryToFindTopicPublishInfo
(
mq
.
getTopic
());
addr
=
this
.
mQClientFactory
.
findBrokerAddressInPublish
(
mq
.
getBrokerName
());
}
}
}
SendMessageContext
context
=
null
;
SendMessageContext
context
=
null
;
if
(
snodeA
ddr
!=
null
)
{
if
(
a
ddr
!=
null
)
{
//brokerAddr = MixAll.brokerVIPChannel(this.defaultMQProducer.isSendMessageWithVIPChannel(), brokerAddr);
//brokerAddr = MixAll.brokerVIPChannel(this.defaultMQProducer.isSendMessageWithVIPChannel(), brokerAddr);
byte
[]
prevBody
=
msg
.
getBody
();
byte
[]
prevBody
=
msg
.
getBody
();
...
@@ -724,7 +736,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -724,7 +736,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
checkForbiddenContext
.
setNameSrvAddr
(
this
.
defaultMQProducer
.
getNamesrvAddr
());
checkForbiddenContext
.
setNameSrvAddr
(
this
.
defaultMQProducer
.
getNamesrvAddr
());
checkForbiddenContext
.
setGroup
(
this
.
defaultMQProducer
.
getProducerGroup
());
checkForbiddenContext
.
setGroup
(
this
.
defaultMQProducer
.
getProducerGroup
());
checkForbiddenContext
.
setCommunicationMode
(
communicationMode
);
checkForbiddenContext
.
setCommunicationMode
(
communicationMode
);
checkForbiddenContext
.
setBrokerAddr
(
snodeA
ddr
);
checkForbiddenContext
.
setBrokerAddr
(
a
ddr
);
checkForbiddenContext
.
setMessage
(
msg
);
checkForbiddenContext
.
setMessage
(
msg
);
checkForbiddenContext
.
setMq
(
mq
);
checkForbiddenContext
.
setMq
(
mq
);
checkForbiddenContext
.
setUnitMode
(
this
.
isUnitMode
());
checkForbiddenContext
.
setUnitMode
(
this
.
isUnitMode
());
...
@@ -737,7 +749,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -737,7 +749,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
context
.
setProducerGroup
(
this
.
defaultMQProducer
.
getProducerGroup
());
context
.
setProducerGroup
(
this
.
defaultMQProducer
.
getProducerGroup
());
context
.
setCommunicationMode
(
communicationMode
);
context
.
setCommunicationMode
(
communicationMode
);
context
.
setBornHost
(
this
.
defaultMQProducer
.
getClientIP
());
context
.
setBornHost
(
this
.
defaultMQProducer
.
getClientIP
());
context
.
setBrokerAddr
(
snodeA
ddr
);
context
.
setBrokerAddr
(
a
ddr
);
context
.
setMessage
(
msg
);
context
.
setMessage
(
msg
);
context
.
setMq
(
mq
);
context
.
setMq
(
mq
);
String
isTrans
=
msg
.
getProperty
(
MessageConst
.
PROPERTY_TRANSACTION_PREPARED
);
String
isTrans
=
msg
.
getProperty
(
MessageConst
.
PROPERTY_TRANSACTION_PREPARED
);
...
@@ -795,7 +807,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -795,7 +807,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
throw
new
RemotingTooMuchRequestException
(
"sendKernelImpl call timeout"
);
throw
new
RemotingTooMuchRequestException
(
"sendKernelImpl call timeout"
);
}
}
sendResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
sendMessage
(
sendResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
sendMessage
(
snodeA
ddr
,
a
ddr
,
mq
.
getBrokerName
(),
mq
.
getBrokerName
(),
tmpMessage
,
tmpMessage
,
requestHeader
,
requestHeader
,
...
@@ -815,7 +827,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
...
@@ -815,7 +827,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
throw
new
RemotingTooMuchRequestException
(
"sendKernelImpl call timeout"
);
throw
new
RemotingTooMuchRequestException
(
"sendKernelImpl call timeout"
);
}
}
sendResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
sendMessage
(
sendResult
=
this
.
mQClientFactory
.
getMQClientAPIImpl
().
sendMessage
(
snodeA
ddr
,
a
ddr
,
mq
.
getBrokerName
(),
mq
.
getBrokerName
(),
msg
,
msg
,
requestHeader
,
requestHeader
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录