Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
db05f817
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
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看板
提交
db05f817
编写于
5月 21, 2021
作者:
Z
zhangjidi2016
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'upstream/develop' into develop
上级
b81e90f0
88add9d4
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
188 addition
and
117 deletion
+188
-117
client/src/main/java/org/apache/rocketmq/client/trace/TraceDataEncoder.java
...va/org/apache/rocketmq/client/trace/TraceDataEncoder.java
+1
-0
client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
...e/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
+33
-49
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQConsumerWithOpenTracingTest.java
...mq/client/trace/DefaultMQConsumerWithOpenTracingTest.java
+32
-48
docs/cn/RocketMQ_Example.md
docs/cn/RocketMQ_Example.md
+1
-1
example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java
.../java/org/apache/rocketmq/example/benchmark/Consumer.java
+2
-2
example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java
.../java/org/apache/rocketmq/example/benchmark/Producer.java
+60
-10
pom.xml
pom.xml
+7
-1
test/src/main/java/org/apache/rocketmq/test/util/data/collect/impl/ListDataCollectorImpl.java
...mq/test/util/data/collect/impl/ListDataCollectorImpl.java
+3
-3
tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java
...he/rocketmq/tools/command/topic/TopicRouteSubCommand.java
+49
-3
未找到文件。
client/src/main/java/org/apache/rocketmq/client/trace/TraceDataEncoder.java
浏览文件 @
db05f817
...
...
@@ -198,6 +198,7 @@ public class TraceDataEncoder {
}
}
break
;
case
EndTransaction:
{
TraceBean
bean
=
ctx
.
getTraceBeans
().
get
(
0
);
sb
.
append
(
ctx
.
getTraceType
()).
append
(
TraceConstants
.
CONTENT_SPLITOR
)
//
...
...
client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java
浏览文件 @
db05f817
...
...
@@ -17,7 +17,6 @@
package
org.apache.rocketmq.client.consumer
;
import
java.io.ByteArrayOutputStream
;
import
java.lang.reflect.Field
;
import
java.net.InetSocketAddress
;
import
java.util.Collections
;
import
java.util.HashSet
;
...
...
@@ -45,7 +44,6 @@ import org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyServic
import
org.apache.rocketmq.client.impl.consumer.ConsumeMessageOrderlyService
;
import
org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl
;
import
org.apache.rocketmq.client.impl.consumer.ProcessQueue
;
import
org.apache.rocketmq.client.impl.consumer.PullAPIWrapper
;
import
org.apache.rocketmq.client.impl.consumer.PullMessageService
;
import
org.apache.rocketmq.client.impl.consumer.PullRequest
;
import
org.apache.rocketmq.client.impl.consumer.PullResultExt
;
...
...
@@ -88,7 +86,6 @@ public class DefaultMQPushConsumerTest {
@Mock
private
MQClientAPIImpl
mQClientAPIImpl
;
private
PullAPIWrapper
pullAPIWrapper
;
private
RebalanceImpl
rebalanceImpl
;
private
DefaultMQPushConsumer
pushConsumer
;
...
...
@@ -98,6 +95,27 @@ public class DefaultMQPushConsumerTest {
factoryTable
.
forEach
((
s
,
instance
)
->
instance
.
shutdown
());
factoryTable
.
clear
();
when
(
mQClientAPIImpl
.
pullMessage
(
anyString
(),
any
(
PullMessageRequestHeader
.
class
),
anyLong
(),
any
(
CommunicationMode
.
class
),
nullable
(
PullCallback
.
class
)))
.
thenAnswer
(
new
Answer
<
PullResult
>()
{
@Override
public
PullResult
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
PullMessageRequestHeader
requestHeader
=
mock
.
getArgument
(
1
);
MessageClientExt
messageClientExt
=
new
MessageClientExt
();
messageClientExt
.
setTopic
(
topic
);
messageClientExt
.
setQueueId
(
0
);
messageClientExt
.
setMsgId
(
"123"
);
messageClientExt
.
setBody
(
new
byte
[]
{
'a'
});
messageClientExt
.
setOffsetMsgId
(
"234"
);
messageClientExt
.
setBornHost
(
new
InetSocketAddress
(
8080
));
messageClientExt
.
setStoreHost
(
new
InetSocketAddress
(
8080
));
PullResult
pullResult
=
createPullResult
(
requestHeader
,
PullStatus
.
FOUND
,
Collections
.<
MessageExt
>
singletonList
(
messageClientExt
));
((
PullCallback
)
mock
.
getArgument
(
4
)).
onSuccess
(
pullResult
);
return
pullResult
;
}
});
consumerGroup
=
"FooBarGroup"
+
System
.
currentTimeMillis
();
pushConsumer
=
new
DefaultMQPushConsumer
(
consumerGroup
);
pushConsumer
.
setNamesrvAddr
(
"127.0.0.1:9876"
);
...
...
@@ -115,58 +133,24 @@ public class DefaultMQPushConsumerTest {
// suppress updateTopicRouteInfoFromNameServer
pushConsumer
.
changeInstanceNameToPID
();
mQClientFactory
=
spy
(
MQClientManager
.
getInstance
().
getOrCreateMQClientInstance
(
pushConsumer
,
(
RPCHook
)
FieldUtils
.
readDeclaredField
(
pushConsumerImpl
,
"rpcHook"
,
true
)));
mQClientFactory
=
MQClientManager
.
getInstance
().
getOrCreateMQClientInstance
(
pushConsumer
,
(
RPCHook
)
FieldUtils
.
readDeclaredField
(
pushConsumerImpl
,
"rpcHook"
,
true
));
FieldUtils
.
writeDeclaredField
(
mQClientFactory
,
"mQClientAPIImpl"
,
mQClientAPIImpl
,
true
);
mQClientFactory
=
spy
(
mQClientFactory
);
factoryTable
.
put
(
pushConsumer
.
buildMQClientId
(),
mQClientFactory
);
doReturn
(
false
).
when
(
mQClientFactory
).
updateTopicRouteInfoFromNameServer
(
anyString
());
rebalanceImpl
=
spy
(
pushConsumer
.
getDefaultMQPushConsumerImpl
().
getRebalanceImpl
());
Field
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"rebalanceImpl"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
rebalanceImpl
);
pushConsumer
.
subscribe
(
topic
,
"*"
);
pushConsumer
.
start
();
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"mQClientFactory"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
mQClientFactory
);
field
=
MQClientInstance
.
class
.
getDeclaredField
(
"mQClientAPIImpl"
);
field
.
setAccessible
(
true
);
field
.
set
(
mQClientFactory
,
mQClientAPIImpl
);
pullAPIWrapper
=
spy
(
new
PullAPIWrapper
(
mQClientFactory
,
consumerGroup
,
false
));
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"pullAPIWrapper"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
pullAPIWrapper
);
mQClientFactory
.
registerConsumer
(
consumerGroup
,
pushConsumerImpl
);
doReturn
(
new
FindBrokerResult
(
"127.0.0.1:10911"
,
false
)).
when
(
mQClientFactory
).
findBrokerAddressInSubscribe
(
anyString
(),
anyLong
(),
anyBoolean
());
when
(
mQClientFactory
.
getMQClientAPIImpl
().
pullMessage
(
anyString
(),
any
(
PullMessageRequestHeader
.
class
),
anyLong
(),
any
(
CommunicationMode
.
class
),
nullable
(
PullCallback
.
class
)))
.
thenAnswer
(
new
Answer
<
PullResult
>()
{
@Override
public
PullResult
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
PullMessageRequestHeader
requestHeader
=
mock
.
getArgument
(
1
);
MessageClientExt
messageClientExt
=
new
MessageClientExt
();
messageClientExt
.
setTopic
(
topic
);
messageClientExt
.
setQueueId
(
0
);
messageClientExt
.
setMsgId
(
"123"
);
messageClientExt
.
setBody
(
new
byte
[]
{
'a'
});
messageClientExt
.
setOffsetMsgId
(
"234"
);
messageClientExt
.
setBornHost
(
new
InetSocketAddress
(
8080
));
messageClientExt
.
setStoreHost
(
new
InetSocketAddress
(
8080
));
PullResult
pullResult
=
createPullResult
(
requestHeader
,
PullStatus
.
FOUND
,
Collections
.<
MessageExt
>
singletonList
(
messageClientExt
));
((
PullCallback
)
mock
.
getArgument
(
4
)).
onSuccess
(
pullResult
);
return
pullResult
;
}
});
rebalanceImpl
=
spy
(
pushConsumerImpl
.
getRebalanceImpl
());
doReturn
(
123L
).
when
(
rebalanceImpl
).
computePullFromWhere
(
any
(
MessageQueue
.
class
));
FieldUtils
.
writeDeclaredField
(
pushConsumerImpl
,
"rebalanceImpl"
,
rebalanceImpl
,
true
);
doReturn
(
new
FindBrokerResult
(
"127.0.0.1:10911"
,
false
)).
when
(
mQClientFactory
).
findBrokerAddressInSubscribe
(
anyString
(),
anyLong
(),
anyBoolean
());
Set
<
MessageQueue
>
messageQueueSet
=
new
HashSet
<
MessageQueue
>();
messageQueueSet
.
add
(
createPullRequest
().
getMessageQueue
());
pushConsumer
.
getDefaultMQPushConsumerImpl
().
updateTopicSubscribeInfo
(
topic
,
messageQueueSet
);
doReturn
(
123L
).
when
(
rebalanceImpl
).
computePullFromWhere
(
any
(
MessageQueue
.
class
));
pushConsumerImpl
.
updateTopicSubscribeInfo
(
topic
,
messageQueueSet
);
pushConsumer
.
subscribe
(
topic
,
"*"
);
pushConsumer
.
start
();
}
@After
...
...
@@ -292,7 +276,7 @@ public class DefaultMQPushConsumerTest {
PullMessageService
pullMessageService
=
mQClientFactory
.
getPullMessageService
();
pullMessageService
.
executePullRequestImmediately
(
createPullRequest
());
assertThat
(
countDownLatch
.
await
(
3
0
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
countDownLatch
.
await
(
1
0
,
TimeUnit
.
SECONDS
)).
isTrue
();
pushConsumer
.
shutdown
();
assertThat
(
messageConsumedFlag
.
get
()).
isTrue
();
...
...
client/src/test/java/org/apache/rocketmq/client/trace/DefaultMQConsumerWithOpenTracingTest.java
浏览文件 @
db05f817
...
...
@@ -21,7 +21,6 @@ import io.opentracing.mock.MockSpan;
import
io.opentracing.mock.MockTracer
;
import
io.opentracing.tag.Tags
;
import
java.io.ByteArrayOutputStream
;
import
java.lang.reflect.Field
;
import
java.net.InetSocketAddress
;
import
java.util.Collections
;
import
java.util.HashSet
;
...
...
@@ -75,6 +74,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import
org.mockito.stubbing.Answer
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
awaitility
.
Awaitility
.
waitAtMost
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyBoolean
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
...
...
@@ -105,6 +105,27 @@ public class DefaultMQConsumerWithOpenTracingTest {
factoryTable
.
forEach
((
s
,
instance
)
->
instance
.
shutdown
());
factoryTable
.
clear
();
when
(
mQClientAPIImpl
.
pullMessage
(
anyString
(),
any
(
PullMessageRequestHeader
.
class
),
anyLong
(),
any
(
CommunicationMode
.
class
),
nullable
(
PullCallback
.
class
)))
.
thenAnswer
(
new
Answer
<
PullResult
>()
{
@Override
public
PullResult
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
PullMessageRequestHeader
requestHeader
=
mock
.
getArgument
(
1
);
MessageClientExt
messageClientExt
=
new
MessageClientExt
();
messageClientExt
.
setTopic
(
topic
);
messageClientExt
.
setQueueId
(
0
);
messageClientExt
.
setMsgId
(
"123"
);
messageClientExt
.
setBody
(
new
byte
[]{
'a'
});
messageClientExt
.
setOffsetMsgId
(
"234"
);
messageClientExt
.
setBornHost
(
new
InetSocketAddress
(
8080
));
messageClientExt
.
setStoreHost
(
new
InetSocketAddress
(
8080
));
PullResult
pullResult
=
createPullResult
(
requestHeader
,
PullStatus
.
FOUND
,
Collections
.<
MessageExt
>
singletonList
(
messageClientExt
));
((
PullCallback
)
mock
.
getArgument
(
4
)).
onSuccess
(
pullResult
);
return
pullResult
;
}
});
consumerGroup
=
"FooBarGroup"
+
System
.
currentTimeMillis
();
pushConsumer
=
new
DefaultMQPushConsumer
(
consumerGroup
);
pushConsumer
.
getDefaultMQPushConsumerImpl
().
registerConsumeMessageHook
(
...
...
@@ -128,58 +149,20 @@ public class DefaultMQConsumerWithOpenTracingTest {
// suppress updateTopicRouteInfoFromNameServer
pushConsumer
.
changeInstanceNameToPID
();
mQClientFactory
=
spy
(
MQClientManager
.
getInstance
().
getOrCreateMQClientInstance
(
pushConsumer
,
(
RPCHook
)
FieldUtils
.
readDeclaredField
(
pushConsumerImpl
,
"rpcHook"
,
true
)));
mQClientFactory
=
MQClientManager
.
getInstance
().
getOrCreateMQClientInstance
(
pushConsumer
,
(
RPCHook
)
FieldUtils
.
readDeclaredField
(
pushConsumerImpl
,
"rpcHook"
,
true
));
FieldUtils
.
writeDeclaredField
(
mQClientFactory
,
"mQClientAPIImpl"
,
mQClientAPIImpl
,
true
);
mQClientFactory
=
spy
(
mQClientFactory
);
factoryTable
.
put
(
pushConsumer
.
buildMQClientId
(),
mQClientFactory
);
doReturn
(
false
).
when
(
mQClientFactory
).
updateTopicRouteInfoFromNameServer
(
anyString
());
rebalancePushImpl
=
spy
(
new
RebalancePushImpl
(
pushConsumer
.
getDefaultMQPushConsumerImpl
()));
Field
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"rebalanceImpl"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
rebalancePushImpl
);
pushConsumer
.
subscribe
(
topic
,
"*"
);
pushConsumer
.
start
();
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"mQClientFactory"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
mQClientFactory
);
field
=
MQClientInstance
.
class
.
getDeclaredField
(
"mQClientAPIImpl"
);
field
.
setAccessible
(
true
);
field
.
set
(
mQClientFactory
,
mQClientAPIImpl
);
pullAPIWrapper
=
spy
(
new
PullAPIWrapper
(
mQClientFactory
,
consumerGroup
,
false
));
field
=
DefaultMQPushConsumerImpl
.
class
.
getDeclaredField
(
"pullAPIWrapper"
);
field
.
setAccessible
(
true
);
field
.
set
(
pushConsumerImpl
,
pullAPIWrapper
);
pushConsumer
.
getDefaultMQPushConsumerImpl
().
getRebalanceImpl
().
setmQClientFactory
(
mQClientFactory
);
mQClientFactory
.
registerConsumer
(
consumerGroup
,
pushConsumerImpl
);
when
(
mQClientAPIImpl
.
pullMessage
(
anyString
(),
any
(
PullMessageRequestHeader
.
class
),
anyLong
(),
any
(
CommunicationMode
.
class
),
nullable
(
PullCallback
.
class
)))
.
thenAnswer
(
new
Answer
<
PullResult
>()
{
@Override
public
PullResult
answer
(
InvocationOnMock
mock
)
throws
Throwable
{
PullMessageRequestHeader
requestHeader
=
mock
.
getArgument
(
1
);
MessageClientExt
messageClientExt
=
new
MessageClientExt
();
messageClientExt
.
setTopic
(
topic
);
messageClientExt
.
setQueueId
(
0
);
messageClientExt
.
setMsgId
(
"123"
);
messageClientExt
.
setBody
(
new
byte
[]{
'a'
});
messageClientExt
.
setOffsetMsgId
(
"234"
);
messageClientExt
.
setBornHost
(
new
InetSocketAddress
(
8080
));
messageClientExt
.
setStoreHost
(
new
InetSocketAddress
(
8080
));
PullResult
pullResult
=
createPullResult
(
requestHeader
,
PullStatus
.
FOUND
,
Collections
.<
MessageExt
>
singletonList
(
messageClientExt
));
((
PullCallback
)
mock
.
getArgument
(
4
)).
onSuccess
(
pullResult
);
return
pullResult
;
}
});
doReturn
(
new
FindBrokerResult
(
"127.0.0.1:10911"
,
false
)).
when
(
mQClientFactory
).
findBrokerAddressInSubscribe
(
anyString
(),
anyLong
(),
anyBoolean
());
Set
<
MessageQueue
>
messageQueueSet
=
new
HashSet
<
MessageQueue
>();
messageQueueSet
.
add
(
createPullRequest
().
getMessageQueue
());
pushConsumer
.
getDefaultMQPushConsumerImpl
().
updateTopicSubscribeInfo
(
topic
,
messageQueueSet
);
pushConsumerImpl
.
updateTopicSubscribeInfo
(
topic
,
messageQueueSet
);
pushConsumer
.
subscribe
(
topic
,
"*"
);
pushConsumer
.
start
();
}
@After
...
...
@@ -209,7 +192,8 @@ public class DefaultMQConsumerWithOpenTracingTest {
assertThat
(
msg
.
getTopic
()).
isEqualTo
(
topic
);
assertThat
(
msg
.
getBody
()).
isEqualTo
(
new
byte
[]{
'a'
});
assertThat
(
tracer
.
finishedSpans
().
size
()).
isEqualTo
(
1
);
// wait until consumeMessageAfter hook of tracer is done surely.
waitAtMost
(
1
,
TimeUnit
.
SECONDS
).
until
(()
->
tracer
.
finishedSpans
().
size
()
==
1
);
MockSpan
span
=
tracer
.
finishedSpans
().
get
(
0
);
assertThat
(
span
.
tags
().
get
(
Tags
.
MESSAGE_BUS_DESTINATION
.
getKey
())).
isEqualTo
(
topic
);
assertThat
(
span
.
tags
().
get
(
Tags
.
SPAN_KIND
.
getKey
())).
isEqualTo
(
Tags
.
SPAN_KIND_CONSUMER
);
...
...
docs/cn/RocketMQ_Example.md
浏览文件 @
db05f817
...
...
@@ -446,7 +446,7 @@ public class ScheduledMessageConsumer {
public
ConsumeConcurrentlyStatus
consumeMessage
(
List
<
MessageExt
>
messages
,
ConsumeConcurrentlyContext
context
)
{
for
(
MessageExt
message
:
messages
)
{
// Print approximate delay time period
System
.
out
.
println
(
"Receive message[msgId="
+
message
.
getMsgId
()
+
"] "
+
(
System
.
currentTimeMillis
()
-
message
.
get
Store
Timestamp
())
+
"ms later"
);
System
.
out
.
println
(
"Receive message[msgId="
+
message
.
getMsgId
()
+
"] "
+
(
System
.
currentTimeMillis
()
-
message
.
get
Born
Timestamp
())
+
"ms later"
);
}
return
ConsumeConcurrentlyStatus
.
CONSUME_SUCCESS
;
}
...
...
example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java
浏览文件 @
db05f817
...
...
@@ -54,7 +54,7 @@ public class Consumer {
final
String
topic
=
commandLine
.
hasOption
(
't'
)
?
commandLine
.
getOptionValue
(
't'
).
trim
()
:
"BenchmarkTest"
;
final
int
threadCount
=
commandLine
.
hasOption
(
'w'
)
?
Integer
.
parseInt
(
commandLine
.
getOptionValue
(
'w'
))
:
20
;
final
String
groupPrefix
=
commandLine
.
hasOption
(
'g'
)
?
commandLine
.
getOptionValue
(
'g'
).
trim
()
:
"benchmark_consumer"
;
final
String
isSuffixEnable
=
commandLine
.
hasOption
(
'p'
)
?
commandLine
.
getOptionValue
(
'p'
).
trim
()
:
"
tru
e"
;
final
String
isSuffixEnable
=
commandLine
.
hasOption
(
'p'
)
?
commandLine
.
getOptionValue
(
'p'
).
trim
()
:
"
fals
e"
;
final
String
filterType
=
commandLine
.
hasOption
(
'f'
)
?
commandLine
.
getOptionValue
(
'f'
).
trim
()
:
null
;
final
String
expression
=
commandLine
.
hasOption
(
'e'
)
?
commandLine
.
getOptionValue
(
'e'
).
trim
()
:
null
;
final
double
failRate
=
commandLine
.
hasOption
(
'r'
)
?
Double
.
parseDouble
(
commandLine
.
getOptionValue
(
'r'
).
trim
())
:
0.0
;
...
...
@@ -190,7 +190,7 @@ public class Consumer {
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
opt
=
new
Option
(
"p"
,
"group
prefix enable"
,
true
,
"Consumer group nam
e, Default: false"
);
opt
=
new
Option
(
"p"
,
"group
suffix enable"
,
true
,
"Consumer group suffix enabl
e, Default: false"
);
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
...
...
example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java
浏览文件 @
db05f817
...
...
@@ -17,12 +17,14 @@
package
org.apache.rocketmq.example.benchmark
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.Random
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.apache.commons.cli.CommandLine
;
...
...
@@ -58,9 +60,10 @@ public class Producer {
final
int
tagCount
=
commandLine
.
hasOption
(
'l'
)
?
Integer
.
parseInt
(
commandLine
.
getOptionValue
(
'l'
))
:
0
;
final
boolean
msgTraceEnable
=
commandLine
.
hasOption
(
'm'
)
&&
Boolean
.
parseBoolean
(
commandLine
.
getOptionValue
(
'm'
));
final
boolean
aclEnable
=
commandLine
.
hasOption
(
'a'
)
&&
Boolean
.
parseBoolean
(
commandLine
.
getOptionValue
(
'a'
));
final
long
messageNum
=
commandLine
.
hasOption
(
'q'
)
?
Long
.
parseLong
(
commandLine
.
getOptionValue
(
'q'
))
:
0
;
System
.
out
.
printf
(
"topic: %s threadCount: %d messageSize: %d keyEnable: %s propertySize: %d tagCount: %d traceEnable: %s aclEnable: %s%n"
,
topic
,
threadCount
,
messageSize
,
keyEnable
,
propertySize
,
tagCount
,
msgTraceEnable
,
aclEnable
);
System
.
out
.
printf
(
"topic: %s threadCount: %d messageSize: %d keyEnable: %s propertySize: %d tagCount: %d traceEnable: %s aclEnable: %s
messageQuantity: %d
%n"
,
topic
,
threadCount
,
messageSize
,
keyEnable
,
propertySize
,
tagCount
,
msgTraceEnable
,
aclEnable
,
messageNum
);
final
InternalLogger
log
=
ClientLogger
.
getLog
();
...
...
@@ -72,6 +75,16 @@ public class Producer {
final
LinkedList
<
Long
[]>
snapshotList
=
new
LinkedList
<
Long
[]>();
final
long
[]
msgNums
=
new
long
[
threadCount
];
if
(
messageNum
>
0
)
{
Arrays
.
fill
(
msgNums
,
messageNum
/
threadCount
);
long
mod
=
messageNum
%
threadCount
;
if
(
mod
>
0
)
{
msgNums
[
0
]
+=
mod
;
}
}
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
@Override
public
void
run
()
{
...
...
@@ -85,14 +98,7 @@ public class Producer {
timer
.
scheduleAtFixedRate
(
new
TimerTask
()
{
private
void
printStats
()
{
if
(
snapshotList
.
size
()
>=
10
)
{
Long
[]
begin
=
snapshotList
.
getFirst
();
Long
[]
end
=
snapshotList
.
getLast
();
final
long
sendTps
=
(
long
)
(((
end
[
3
]
-
begin
[
3
])
/
(
double
)
(
end
[
0
]
-
begin
[
0
]))
*
1000L
);
final
double
averageRT
=
(
end
[
5
]
-
begin
[
5
])
/
(
double
)
(
end
[
3
]
-
begin
[
3
]);
System
.
out
.
printf
(
"Current Time: %s Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
System
.
currentTimeMillis
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
doPrintStats
(
snapshotList
,
statsBenchmark
,
false
);
}
}
...
...
@@ -120,9 +126,14 @@ public class Producer {
producer
.
start
();
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
final
long
msgNumLimit
=
msgNums
[
i
];
if
(
messageNum
>
0
&&
msgNumLimit
==
0
)
{
break
;
}
sendThreadPool
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
int
num
=
0
;
while
(
true
)
{
try
{
final
Message
msg
;
...
...
@@ -198,10 +209,28 @@ public class Producer {
}
catch
(
InterruptedException
ignored
)
{
}
}
if
(
messageNum
>
0
&&
++
num
>=
msgNumLimit
)
{
break
;
}
}
}
});
}
try
{
sendThreadPool
.
shutdown
();
sendThreadPool
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
DAYS
);
timer
.
cancel
();
if
(
snapshotList
.
size
()
>
1
)
{
doPrintStats
(
snapshotList
,
statsBenchmark
,
true
);
}
else
{
System
.
out
.
printf
(
"[Complete] Send Total: %d Send Failed: %d Response Failed: %d%n"
,
statsBenchmark
.
getSendRequestSuccessCount
().
get
()
+
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
statsBenchmark
.
getReceiveResponseFailedCount
().
get
());
}
producer
.
shutdown
();
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"[Exit] Thread Interrupted Exception"
,
e
);
}
}
public
static
Options
buildCommandlineOptions
(
final
Options
options
)
{
...
...
@@ -233,6 +262,10 @@ public class Producer {
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
opt
=
new
Option
(
"q"
,
"messageQuantity"
,
true
,
"Send message quantity, Default: 0, running forever"
);
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
return
options
;
}
...
...
@@ -249,6 +282,23 @@ public class Producer {
return
msg
;
}
private
static
void
doPrintStats
(
final
LinkedList
<
Long
[]>
snapshotList
,
final
StatsBenchmarkProducer
statsBenchmark
,
boolean
done
)
{
Long
[]
begin
=
snapshotList
.
getFirst
();
Long
[]
end
=
snapshotList
.
getLast
();
final
long
sendTps
=
(
long
)
(((
end
[
3
]
-
begin
[
3
])
/
(
double
)
(
end
[
0
]
-
begin
[
0
]))
*
1000L
);
final
double
averageRT
=
(
end
[
5
]
-
begin
[
5
])
/
(
double
)
(
end
[
3
]
-
begin
[
3
]);
if
(
done
)
{
System
.
out
.
printf
(
"[Complete] Send Total: %d Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
statsBenchmark
.
getSendRequestSuccessCount
().
get
()
+
statsBenchmark
.
getSendRequestFailedCount
().
get
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
}
else
{
System
.
out
.
printf
(
"Current Time: %s Send TPS: %d Max RT(ms): %d Average RT(ms): %7.3f Send Failed: %d Response Failed: %d%n"
,
System
.
currentTimeMillis
(),
sendTps
,
statsBenchmark
.
getSendMessageMaxRT
().
get
(),
averageRT
,
end
[
2
],
end
[
4
]);
}
}
}
class
StatsBenchmarkProducer
{
...
...
pom.xml
浏览文件 @
db05f817
...
...
@@ -439,6 +439,12 @@
<version>
3.10.0
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.awaitility
</groupId>
<artifactId>
awaitility
</artifactId>
<version>
4.1.0
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<dependencyManagement>
...
...
@@ -536,7 +542,7 @@
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.
69
</version>
<version>
1.2.
76
</version>
</dependency>
<dependency>
<groupId>
org.javassist
</groupId>
...
...
test/src/main/java/org/apache/rocketmq/test/util/data/collect/impl/ListDataCollectorImpl.java
浏览文件 @
db05f817
...
...
@@ -43,7 +43,7 @@ public class ListDataCollectorImpl implements DataCollector {
return
datas
;
}
public
void
resetData
()
{
public
synchronized
void
resetData
()
{
datas
.
clear
();
unlockIncrement
();
}
...
...
@@ -67,7 +67,7 @@ public class ListDataCollectorImpl implements DataCollector {
return
Collections
.
frequency
(
datas
,
data
)
==
1
;
}
public
Collection
<
Object
>
getAllDataWithoutDuplicate
()
{
public
synchronized
Collection
<
Object
>
getAllDataWithoutDuplicate
()
{
return
new
HashSet
<
Object
>(
datas
);
}
...
...
@@ -81,7 +81,7 @@ public class ListDataCollectorImpl implements DataCollector {
return
res
;
}
public
void
removeData
(
Object
data
)
{
public
synchronized
void
removeData
(
Object
data
)
{
datas
.
remove
(
data
);
}
...
...
tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java
浏览文件 @
db05f817
...
...
@@ -19,14 +19,23 @@ package org.apache.rocketmq.tools.command.topic;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Options
;
import
org.apache.rocketmq.common.protocol.route.BrokerData
;
import
org.apache.rocketmq.common.protocol.route.QueueData
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
;
import
org.apache.rocketmq.remoting.RPCHook
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.command.SubCommand
;
import
org.apache.rocketmq.tools.command.SubCommandException
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
TopicRouteSubCommand
implements
SubCommand
{
private
static
final
String
FORMAT
=
"%-45s %-32s %-50s %-10s %-11s %-5s%n"
;
@Override
public
String
commandName
()
{
return
"topicRoute"
;
...
...
@@ -43,6 +52,9 @@ public class TopicRouteSubCommand implements SubCommand {
opt
.
setRequired
(
true
);
options
.
addOption
(
opt
);
opt
=
new
Option
(
"l"
,
"list"
,
false
,
"Use list format to print data"
);
opt
.
setRequired
(
false
);
options
.
addOption
(
opt
);
return
options
;
}
...
...
@@ -58,12 +70,46 @@ public class TopicRouteSubCommand implements SubCommand {
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
TopicRouteData
topicRouteData
=
defaultMQAdminExt
.
examineTopicRouteInfo
(
topic
);
String
json
=
topicRouteData
.
toJson
(
true
);
System
.
out
.
printf
(
"%s%n"
,
json
);
printData
(
topicRouteData
,
commandLine
.
hasOption
(
'l'
));
}
catch
(
Exception
e
)
{
throw
new
SubCommandException
(
this
.
getClass
().
getSimpleName
()
+
" command failed"
,
e
);
}
finally
{
defaultMQAdminExt
.
shutdown
();
}
}
}
private
void
printData
(
TopicRouteData
topicRouteData
,
boolean
useListFormat
)
{
if
(!
useListFormat
)
{
System
.
out
.
printf
(
"%s%n"
,
topicRouteData
.
toJson
(
true
));
return
;
}
int
totalReadQueue
=
0
,
totalWriteQueue
=
0
;
List
<
QueueData
>
queueDataList
=
topicRouteData
.
getQueueDatas
();
Map
<
String
/*brokerName*/
,
QueueData
>
map
=
new
HashMap
<>();
for
(
QueueData
queueData
:
queueDataList
)
{
map
.
put
(
queueData
.
getBrokerName
(),
queueData
);
}
queueDataList
.
sort
(
Comparator
.
comparing
(
QueueData:
:
getBrokerName
));
List
<
BrokerData
>
brokerDataList
=
topicRouteData
.
getBrokerDatas
();
brokerDataList
.
sort
(
Comparator
.
comparing
(
BrokerData:
:
getBrokerName
));
System
.
out
.
printf
(
FORMAT
,
"#ClusterName"
,
"#BrokerName"
,
"#BrokerAddrs"
,
"#ReadQueue"
,
"#WriteQueue"
,
"#Perm"
);
for
(
BrokerData
brokerData
:
brokerDataList
)
{
String
brokerName
=
brokerData
.
getBrokerName
();
QueueData
queueData
=
map
.
get
(
brokerName
);
totalReadQueue
+=
queueData
.
getReadQueueNums
();
totalWriteQueue
+=
queueData
.
getWriteQueueNums
();
System
.
out
.
printf
(
FORMAT
,
brokerData
.
getCluster
(),
brokerName
,
brokerData
.
getBrokerAddrs
(),
queueData
.
getReadQueueNums
(),
queueData
.
getWriteQueueNums
(),
queueData
.
getPerm
());
}
for
(
int
i
=
0
;
i
<
158
;
i
++)
{
System
.
out
.
print
(
"-"
);
}
System
.
out
.
printf
(
"%n"
);
System
.
out
.
printf
(
FORMAT
,
"Total:"
,
map
.
keySet
().
size
(),
""
,
totalReadQueue
,
totalWriteQueue
,
""
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录