Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
3530b76e
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看板
提交
3530b76e
编写于
11月 02, 2018
作者:
M
maowei.ymw
提交者:
von gosling
11月 27, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MQPullConsumer support MessageSelector
上级
3c524c20
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
157 addition
and
53 deletion
+157
-53
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java
...pache/rocketmq/client/consumer/DefaultMQPullConsumer.java
+26
-0
client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java
...a/org/apache/rocketmq/client/consumer/MQPullConsumer.java
+47
-0
client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java
...ketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java
+70
-25
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
.../apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
+1
-28
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java
...apache/rocketmq/client/impl/factory/MQClientInstance.java
+13
-0
未找到文件。
client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java
浏览文件 @
3530b76e
...
...
@@ -257,6 +257,18 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume
return
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
subExpression
,
offset
,
maxNums
,
timeout
);
}
@Override
public
PullResult
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
messageSelector
,
offset
,
maxNums
);
}
@Override
public
PullResult
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
messageSelector
,
offset
,
maxNums
,
timeout
);
}
@Override
public
void
pull
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
...
...
@@ -270,6 +282,20 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
subExpression
,
offset
,
maxNums
,
pullCallback
,
timeout
);
}
@Override
public
void
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
messageSelector
,
offset
,
maxNums
,
pullCallback
);
}
@Override
public
void
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
this
.
defaultMQPullConsumerImpl
.
pull
(
mq
,
messageSelector
,
offset
,
maxNums
,
pullCallback
,
timeout
);
}
@Override
public
PullResult
pullBlockIfNotFound
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
...
...
client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java
浏览文件 @
3530b76e
...
...
@@ -66,6 +66,39 @@ public interface MQPullConsumer extends MQConsumer {
final
int
maxNums
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
;
/**
* Pulling the messages, not blocking
* <p>
* support other message selection, such as {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92}
* </p>
*
* @param mq from which message queue
* @param selector message selector({@link MessageSelector}), can be null.
* @param offset from where to pull
* @param maxNums max pulling numbers
* @return The resulting {@code PullRequest}
*/
PullResult
pull
(
final
MessageQueue
mq
,
final
MessageSelector
selector
,
final
long
offset
,
final
int
maxNums
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
;
/**
* Pulling the messages in the specified timeout
* <p>
* support other message selection, such as {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92}
* </p>
*
* @param mq from which message queue
* @param selector message selector({@link MessageSelector}), can be null.
* @param offset from where to pull
* @param maxNums max pulling numbers
* @param timeout Pulling the messages in the specified timeout
* @return The resulting {@code PullRequest}
*/
PullResult
pull
(
final
MessageQueue
mq
,
final
MessageSelector
selector
,
final
long
offset
,
final
int
maxNums
,
final
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
;
/**
* Pulling the messages in a async. way
*/
...
...
@@ -80,6 +113,20 @@ public interface MQPullConsumer extends MQConsumer {
final
PullCallback
pullCallback
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
;
/**
* Pulling the messages in a async. way. Support message selection
*/
void
pull
(
final
MessageQueue
mq
,
final
MessageSelector
selector
,
final
long
offset
,
final
int
maxNums
,
final
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
InterruptedException
;
/**
* Pulling the messages in a async. way. Support message selection
*/
void
pull
(
final
MessageQueue
mq
,
final
MessageSelector
selector
,
final
long
offset
,
final
int
maxNums
,
final
PullCallback
pullCallback
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
;
/**
* Pulling the messages,if no message arrival,blocking some time
*
...
...
client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java
浏览文件 @
3530b76e
...
...
@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import
org.apache.rocketmq.client.QueryResult
;
import
org.apache.rocketmq.client.Validators
;
import
org.apache.rocketmq.client.consumer.DefaultMQPullConsumer
;
import
org.apache.rocketmq.client.consumer.MessageSelector
;
import
org.apache.rocketmq.client.consumer.PullCallback
;
import
org.apache.rocketmq.client.consumer.PullResult
;
import
org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus
;
...
...
@@ -158,17 +159,58 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
public
PullResult
pull
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
this
.
pullSyncImpl
(
mq
,
subExpression
,
offset
,
maxNums
,
false
,
timeout
);
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
subExpression
);
return
this
.
pullSyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
false
,
timeout
);
}
private
PullResult
pullSyncImpl
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
,
boolean
block
,
public
PullResult
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
pull
(
mq
,
messageSelector
,
offset
,
maxNums
,
this
.
defaultMQPullConsumer
.
getConsumerPullTimeoutMillis
());
}
public
PullResult
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
messageSelector
);
return
this
.
pullSyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
false
,
timeout
);
}
private
SubscriptionData
getSubscriptionData
(
MessageQueue
mq
,
String
subExpression
)
throws
MQClientException
{
if
(
null
==
mq
)
{
throw
new
MQClientException
(
"mq is null"
,
null
);
}
try
{
return
FilterAPI
.
buildSubscriptionData
(
this
.
defaultMQPullConsumer
.
getConsumerGroup
(),
mq
.
getTopic
(),
subExpression
);
}
catch
(
Exception
e
)
{
throw
new
MQClientException
(
"parse subscription error"
,
e
);
}
}
private
SubscriptionData
getSubscriptionData
(
MessageQueue
mq
,
MessageSelector
messageSelector
)
throws
MQClientException
{
if
(
null
==
mq
)
{
throw
new
MQClientException
(
"mq is null"
,
null
);
}
try
{
return
FilterAPI
.
build
(
mq
.
getTopic
(),
messageSelector
.
getExpression
(),
messageSelector
.
getExpressionType
());
}
catch
(
Exception
e
)
{
throw
new
MQClientException
(
"parse subscription error"
,
e
);
}
}
private
PullResult
pullSyncImpl
(
MessageQueue
mq
,
SubscriptionData
subscriptionData
,
long
offset
,
int
maxNums
,
boolean
block
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
this
.
makeSureStateOK
();
if
(
null
==
mq
)
{
throw
new
MQClientException
(
"mq is null"
,
null
);
}
if
(
offset
<
0
)
{
...
...
@@ -183,20 +225,13 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
int
sysFlag
=
PullSysFlag
.
buildSysFlag
(
false
,
block
,
true
,
false
);
SubscriptionData
subscriptionData
;
try
{
subscriptionData
=
FilterAPI
.
buildSubscriptionData
(
this
.
defaultMQPullConsumer
.
getConsumerGroup
(),
mq
.
getTopic
(),
subExpression
);
}
catch
(
Exception
e
)
{
throw
new
MQClientException
(
"parse subscription error"
,
e
);
}
long
timeoutMillis
=
block
?
this
.
defaultMQPullConsumer
.
getConsumerTimeoutMillisWhenSuspend
()
:
timeout
;
PullResult
pullResult
=
this
.
pullAPIWrapper
.
pullKernelImpl
(
mq
,
subscriptionData
.
getSubString
(),
0L
,
subscriptionData
.
getExpressionType
(),
subscriptionData
.
getSubVersion
(),
offset
,
maxNums
,
sysFlag
,
...
...
@@ -369,12 +404,27 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
public
void
pull
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
this
.
pullAsyncImpl
(
mq
,
subExpression
,
offset
,
maxNums
,
pullCallback
,
false
,
timeout
);
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
subExpression
);
this
.
pullAsyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
pullCallback
,
false
,
timeout
);
}
public
void
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
pull
(
mq
,
messageSelector
,
offset
,
maxNums
,
pullCallback
,
this
.
defaultMQPullConsumer
.
getConsumerPullTimeoutMillis
());
}
public
void
pull
(
MessageQueue
mq
,
MessageSelector
messageSelector
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
,
long
timeout
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
messageSelector
);
this
.
pullAsyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
pullCallback
,
false
,
timeout
);
}
private
void
pullAsyncImpl
(
final
MessageQueue
mq
,
final
S
tring
subExpression
,
final
S
ubscriptionData
subscriptionData
,
final
long
offset
,
final
int
maxNums
,
final
PullCallback
pullCallback
,
...
...
@@ -403,20 +453,13 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
try
{
int
sysFlag
=
PullSysFlag
.
buildSysFlag
(
false
,
block
,
true
,
false
);
final
SubscriptionData
subscriptionData
;
try
{
subscriptionData
=
FilterAPI
.
buildSubscriptionData
(
this
.
defaultMQPullConsumer
.
getConsumerGroup
(),
mq
.
getTopic
(),
subExpression
);
}
catch
(
Exception
e
)
{
throw
new
MQClientException
(
"parse subscription error"
,
e
);
}
long
timeoutMillis
=
block
?
this
.
defaultMQPullConsumer
.
getConsumerTimeoutMillisWhenSuspend
()
:
timeout
;
this
.
pullAPIWrapper
.
pullKernelImpl
(
mq
,
subscriptionData
.
getSubString
(),
0L
,
subscriptionData
.
getExpressionType
(),
subscriptionData
.
getSubVersion
(),
offset
,
maxNums
,
sysFlag
,
...
...
@@ -444,7 +487,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
public
PullResult
pullBlockIfNotFound
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
this
.
pullSyncImpl
(
mq
,
subExpression
,
offset
,
maxNums
,
true
,
this
.
getDefaultMQPullConsumer
().
getConsumerPullTimeoutMillis
());
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
subExpression
);
return
this
.
pullSyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
true
,
this
.
getDefaultMQPullConsumer
().
getConsumerPullTimeoutMillis
());
}
public
DefaultMQPullConsumer
getDefaultMQPullConsumer
()
{
...
...
@@ -454,7 +498,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner {
public
void
pullBlockIfNotFound
(
MessageQueue
mq
,
String
subExpression
,
long
offset
,
int
maxNums
,
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
InterruptedException
{
this
.
pullAsyncImpl
(
mq
,
subExpression
,
offset
,
maxNums
,
pullCallback
,
true
,
SubscriptionData
subscriptionData
=
getSubscriptionData
(
mq
,
subExpression
);
this
.
pullAsyncImpl
(
mq
,
subscriptionData
,
offset
,
maxNums
,
pullCallback
,
true
,
this
.
getDefaultMQPullConsumer
().
getConsumerPullTimeoutMillis
());
}
...
...
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
浏览文件 @
3530b76e
...
...
@@ -163,6 +163,7 @@ public class PullAPIWrapper {
this
.
recalculatePullFromWhichNode
(
mq
),
false
);
}
if
(
findBrokerResult
!=
null
)
{
{
// check version
...
...
@@ -209,34 +210,6 @@ public class PullAPIWrapper {
throw
new
MQClientException
(
"The broker["
+
mq
.
getBrokerName
()
+
"] not exist"
,
null
);
}
public
PullResult
pullKernelImpl
(
final
MessageQueue
mq
,
final
String
subExpression
,
final
long
subVersion
,
final
long
offset
,
final
int
maxNums
,
final
int
sysFlag
,
final
long
commitOffset
,
final
long
brokerSuspendMaxTimeMillis
,
final
long
timeoutMillis
,
final
CommunicationMode
communicationMode
,
final
PullCallback
pullCallback
)
throws
MQClientException
,
RemotingException
,
MQBrokerException
,
InterruptedException
{
return
pullKernelImpl
(
mq
,
subExpression
,
ExpressionType
.
TAG
,
subVersion
,
offset
,
maxNums
,
sysFlag
,
commitOffset
,
brokerSuspendMaxTimeMillis
,
timeoutMillis
,
communicationMode
,
pullCallback
);
}
public
long
recalculatePullFromWhichNode
(
final
MessageQueue
mq
)
{
if
(
this
.
isConnectBrokerByUser
())
{
return
this
.
defaultBrokerId
;
...
...
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java
浏览文件 @
3530b76e
...
...
@@ -1046,6 +1046,19 @@ public class MQClientInstance {
if
(
this
.
brokerVersionTable
.
get
(
brokerName
).
containsKey
(
brokerAddr
))
{
return
this
.
brokerVersionTable
.
get
(
brokerName
).
get
(
brokerAddr
);
}
}
else
{
HeartbeatData
heartbeatData
=
prepareHeartbeatData
();
try
{
int
version
=
this
.
mQClientAPIImpl
.
sendHearbeat
(
brokerAddr
,
heartbeatData
,
3000
);
return
version
;
}
catch
(
Exception
e
)
{
if
(
this
.
isBrokerInNameServer
(
brokerAddr
))
{
log
.
info
(
"send heart beat to broker[{} {}] failed"
,
brokerName
,
brokerAddr
);
}
else
{
log
.
info
(
"send heart beat to broker[{} {}] exception, because the broker not up, forget it"
,
brokerName
,
brokerAddr
);
}
}
}
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录