Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
6f2b1208
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看板
提交
6f2b1208
编写于
11月 29, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish the basic create,produce,consume of the static topic
上级
ed2d6267
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
133 addition
and
173 deletion
+133
-173
broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java
...pache/rocketmq/broker/processor/PullMessageProcessor.java
+68
-163
client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java
.../java/org/apache/rocketmq/client/consumer/PullResult.java
+1
-0
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
+4
-0
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java
...g/apache/rocketmq/client/impl/consumer/PullResultExt.java
+12
-0
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
...st/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
+47
-9
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java
浏览文件 @
6f2b1208
此差异已折叠。
点击以展开。
client/src/main/java/org/apache/rocketmq/client/consumer/PullResult.java
浏览文件 @
6f2b1208
...
@@ -26,6 +26,7 @@ public class PullResult {
...
@@ -26,6 +26,7 @@ public class PullResult {
private
final
long
maxOffset
;
private
final
long
maxOffset
;
private
List
<
MessageExt
>
msgFoundList
;
private
List
<
MessageExt
>
msgFoundList
;
public
PullResult
(
PullStatus
pullStatus
,
long
nextBeginOffset
,
long
minOffset
,
long
maxOffset
,
public
PullResult
(
PullStatus
pullStatus
,
long
nextBeginOffset
,
long
minOffset
,
long
maxOffset
,
List
<
MessageExt
>
msgFoundList
)
{
List
<
MessageExt
>
msgFoundList
)
{
super
();
super
();
...
...
client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
浏览文件 @
6f2b1208
...
@@ -973,7 +973,7 @@ public class MQClientAPIImpl {
...
@@ -973,7 +973,7 @@ public class MQClientAPIImpl {
(
PullMessageResponseHeader
)
response
.
decodeCommandCustomHeader
(
PullMessageResponseHeader
.
class
);
(
PullMessageResponseHeader
)
response
.
decodeCommandCustomHeader
(
PullMessageResponseHeader
.
class
);
return
new
PullResultExt
(
pullStatus
,
responseHeader
.
getNextBeginOffset
(),
responseHeader
.
getMinOffset
(),
return
new
PullResultExt
(
pullStatus
,
responseHeader
.
getNextBeginOffset
(),
responseHeader
.
getMinOffset
(),
responseHeader
.
getMaxOffset
(),
null
,
responseHeader
.
getSuggestWhichBrokerId
(),
response
.
getBody
());
responseHeader
.
getMaxOffset
(),
null
,
responseHeader
.
getSuggestWhichBrokerId
(),
response
.
getBody
()
,
responseHeader
.
getOffsetDelta
()
);
}
}
private
PopResult
processPopResponse
(
final
String
brokerName
,
final
RemotingCommand
response
,
String
topic
,
private
PopResult
processPopResponse
(
final
String
brokerName
,
final
RemotingCommand
response
,
String
topic
,
...
...
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullAPIWrapper.java
浏览文件 @
6f2b1208
...
@@ -107,6 +107,10 @@ public class PullAPIWrapper {
...
@@ -107,6 +107,10 @@ public class PullAPIWrapper {
MessageAccessor
.
putProperty
(
msg
,
MessageConst
.
PROPERTY_MAX_OFFSET
,
MessageAccessor
.
putProperty
(
msg
,
MessageConst
.
PROPERTY_MAX_OFFSET
,
Long
.
toString
(
pullResult
.
getMaxOffset
()));
Long
.
toString
(
pullResult
.
getMaxOffset
()));
msg
.
setBrokerName
(
mq
.
getBrokerName
());
msg
.
setBrokerName
(
mq
.
getBrokerName
());
msg
.
setQueueId
(
mq
.
getQueueId
());
if
(
pullResultExt
.
getOffsetDelta
()
!=
null
)
{
msg
.
setQueueOffset
(
pullResultExt
.
getOffsetDelta
()
+
msg
.
getQueueOffset
());
}
}
}
pullResultExt
.
setMsgFoundList
(
msgListFilterAgain
);
pullResultExt
.
setMsgFoundList
(
msgListFilterAgain
);
...
...
client/src/main/java/org/apache/rocketmq/client/impl/consumer/PullResultExt.java
浏览文件 @
6f2b1208
...
@@ -25,11 +25,23 @@ public class PullResultExt extends PullResult {
...
@@ -25,11 +25,23 @@ public class PullResultExt extends PullResult {
private
final
long
suggestWhichBrokerId
;
private
final
long
suggestWhichBrokerId
;
private
byte
[]
messageBinary
;
private
byte
[]
messageBinary
;
private
final
Long
offsetDelta
;
public
PullResultExt
(
PullStatus
pullStatus
,
long
nextBeginOffset
,
long
minOffset
,
long
maxOffset
,
public
PullResultExt
(
PullStatus
pullStatus
,
long
nextBeginOffset
,
long
minOffset
,
long
maxOffset
,
List
<
MessageExt
>
msgFoundList
,
final
long
suggestWhichBrokerId
,
final
byte
[]
messageBinary
)
{
List
<
MessageExt
>
msgFoundList
,
final
long
suggestWhichBrokerId
,
final
byte
[]
messageBinary
)
{
this
(
pullStatus
,
nextBeginOffset
,
minOffset
,
maxOffset
,
msgFoundList
,
suggestWhichBrokerId
,
messageBinary
,
0L
);
}
public
PullResultExt
(
PullStatus
pullStatus
,
long
nextBeginOffset
,
long
minOffset
,
long
maxOffset
,
List
<
MessageExt
>
msgFoundList
,
final
long
suggestWhichBrokerId
,
final
byte
[]
messageBinary
,
final
Long
offsetDelta
)
{
super
(
pullStatus
,
nextBeginOffset
,
minOffset
,
maxOffset
,
msgFoundList
);
super
(
pullStatus
,
nextBeginOffset
,
minOffset
,
maxOffset
,
msgFoundList
);
this
.
suggestWhichBrokerId
=
suggestWhichBrokerId
;
this
.
suggestWhichBrokerId
=
suggestWhichBrokerId
;
this
.
messageBinary
=
messageBinary
;
this
.
messageBinary
=
messageBinary
;
this
.
offsetDelta
=
offsetDelta
;
}
public
Long
getOffsetDelta
()
{
return
offsetDelta
;
}
}
public
byte
[]
getMessageBinary
()
{
public
byte
[]
getMessageBinary
()
{
...
...
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
浏览文件 @
6f2b1208
...
@@ -2,6 +2,9 @@ package org.apache.rocketmq.test.smoke;
...
@@ -2,6 +2,9 @@ package org.apache.rocketmq.test.smoke;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.message.MessageClientExt
;
import
org.apache.rocketmq.common.message.MessageConst
;
import
org.apache.rocketmq.common.message.MessageExt
;
import
org.apache.rocketmq.common.message.MessageQueue
;
import
org.apache.rocketmq.common.message.MessageQueue
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.rpc.ClientMetadata
;
import
org.apache.rocketmq.common.rpc.ClientMetadata
;
...
@@ -9,8 +12,11 @@ import org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping;
...
@@ -9,8 +12,11 @@ import org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalConsumer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
import
org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener
;
import
org.apache.rocketmq.test.util.MQRandomUtils
;
import
org.apache.rocketmq.test.util.MQRandomUtils
;
import
org.apache.rocketmq.test.util.VerifyUtils
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Assert
;
...
@@ -19,11 +25,15 @@ import org.junit.FixMethodOrder;
...
@@ -19,11 +25,15 @@ import org.junit.FixMethodOrder;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
apache
.
rocketmq
.
common
.
statictopic
.
TopicQueueMappingUtils
.
getMappingDetailFromConfig
;
import
static
org
.
apache
.
rocketmq
.
common
.
statictopic
.
TopicQueueMappingUtils
.
getMappingDetailFromConfig
;
@FixMethodOrder
@FixMethodOrder
...
@@ -63,11 +73,16 @@ public class StaticTopicIT extends BaseConf {
...
@@ -63,11 +73,16 @@ public class StaticTopicIT extends BaseConf {
}
}
@Test
@Test
public
void
testCreate
AndRemapping
StaticTopic
()
throws
Exception
{
public
void
testCreate
ProduceConsume
StaticTopic
()
throws
Exception
{
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
RMQNormalProducer
producer
=
getProducer
(
nsAddr
,
topic
);
RMQNormalProducer
producer
=
getProducer
(
nsAddr
,
topic
);
RMQNormalConsumer
consumer
=
getConsumer
(
nsAddr
,
topic
,
"*"
,
new
RMQNormalListener
());
int
queueNum
=
10
;
int
queueNum
=
10
;
int
msgEachQueue
=
100
;
//create static topic
Map
<
String
,
TopicConfigAndQueueMapping
>
localBrokerConfigMap
=
createStaticTopic
(
topic
,
queueNum
,
getBrokers
());
Map
<
String
,
TopicConfigAndQueueMapping
>
localBrokerConfigMap
=
createStaticTopic
(
topic
,
queueNum
,
getBrokers
());
//check the static topic config
{
{
Map
<
String
,
TopicConfigAndQueueMapping
>
remoteBrokerConfigMap
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
Map
<
String
,
TopicConfigAndQueueMapping
>
remoteBrokerConfigMap
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
Assert
.
assertEquals
(
2
,
remoteBrokerConfigMap
.
size
());
Assert
.
assertEquals
(
2
,
remoteBrokerConfigMap
.
size
());
...
@@ -82,6 +97,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -82,6 +97,7 @@ public class StaticTopicIT extends BaseConf {
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
new
ArrayList
<>(
getMappingDetailFromConfig
(
remoteBrokerConfigMap
.
values
())),
false
,
true
);
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
new
ArrayList
<>(
getMappingDetailFromConfig
(
remoteBrokerConfigMap
.
values
())),
false
,
true
);
Assert
.
assertEquals
(
queueNum
,
globalIdMap
.
size
());
Assert
.
assertEquals
(
queueNum
,
globalIdMap
.
size
());
}
}
//check the route data
List
<
MessageQueue
>
messageQueueList
=
producer
.
getMessageQueue
();
List
<
MessageQueue
>
messageQueueList
=
producer
.
getMessageQueue
();
Assert
.
assertEquals
(
queueNum
,
messageQueueList
.
size
());
Assert
.
assertEquals
(
queueNum
,
messageQueueList
.
size
());
producer
.
setDebug
(
true
);
producer
.
setDebug
(
true
);
...
@@ -91,23 +107,45 @@ public class StaticTopicIT extends BaseConf {
...
@@ -91,23 +107,45 @@ public class StaticTopicIT extends BaseConf {
Assert
.
assertEquals
(
i
,
messageQueue
.
getQueueId
());
Assert
.
assertEquals
(
i
,
messageQueue
.
getQueueId
());
Assert
.
assertEquals
(
MixAll
.
LOGICAL_QUEUE_MOCK_BROKER_NAME
,
messageQueue
.
getBrokerName
());
Assert
.
assertEquals
(
MixAll
.
LOGICAL_QUEUE_MOCK_BROKER_NAME
,
messageQueue
.
getBrokerName
());
}
}
//send and consume the msg
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
producer
.
send
(
100
,
messageQueue
);
producer
.
send
(
msgEachQueue
,
messageQueue
);
}
}
//leave the time to build the cq
//leave the time to build the cq
Thread
.
sleep
(
500
);
Thread
.
sleep
(
500
);
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
Assert
.
assertEquals
(
0
,
defaultMQAdminExt
.
minOffset
(
messageQueue
));
Assert
.
assertEquals
(
0
,
defaultMQAdminExt
.
minOffset
(
messageQueue
));
Assert
.
assertEquals
(
100
,
defaultMQAdminExt
.
maxOffset
(
messageQueue
));
Assert
.
assertEquals
(
msgEachQueue
,
defaultMQAdminExt
.
maxOffset
(
messageQueue
));
}
}
Assert
.
assertEquals
(
100
*
queueNum
,
producer
.
getAllOriginMsg
().
size
());
Assert
.
assertEquals
(
msgEachQueue
*
queueNum
,
producer
.
getAllOriginMsg
().
size
());
Assert
.
assertEquals
(
0
,
producer
.
getSendErrorMsg
().
size
());
Assert
.
assertEquals
(
0
,
producer
.
getSendErrorMsg
().
size
());
/*{
Set<String> targetBrokers = Collections.singleton(broker1Name);
Map<String, TopicConfigAndQueueMapping> brokerConfigMapFromRemote = defaultMQAdminExt.examineTopicConfigAll(clientMetadata, topic);
TopicRemappingDetailWrapper wrapper = TopicQueueMappingUtils.remappingStaticTopic(topic, brokerConfigMapFromRemote, targetBrokers);
}*/
consumer
.
getListener
().
waitForMessageConsume
(
producer
.
getAllMsgBody
(),
consumeTime
);
assertThat
(
VerifyUtils
.
getFilterdMessage
(
producer
.
getAllMsgBody
(),
consumer
.
getListener
().
getAllMsgBody
()))
.
containsExactlyElementsIn
(
producer
.
getAllMsgBody
());
Map
<
Integer
,
List
<
MessageExt
>>
messagesByQueue
=
new
HashMap
<>();
for
(
Object
object
:
consumer
.
getListener
().
getAllOriginMsg
())
{
MessageExt
messageExt
=
(
MessageExt
)
object
;
if
(!
messagesByQueue
.
containsKey
(
messageExt
.
getQueueId
()))
{
messagesByQueue
.
put
(
messageExt
.
getQueueId
(),
new
ArrayList
<>());
}
messagesByQueue
.
get
(
messageExt
.
getQueueId
()).
add
(
messageExt
);
}
Assert
.
assertEquals
(
queueNum
,
messagesByQueue
.
size
());
for
(
int
i
=
0
;
i
<
queueNum
;
i
++)
{
List
<
MessageExt
>
messageExts
=
messagesByQueue
.
get
(
i
);
Assert
.
assertEquals
(
msgEachQueue
,
messageExts
.
size
());
Collections
.
sort
(
messageExts
,
new
Comparator
<
MessageExt
>()
{
@Override
public
int
compare
(
MessageExt
o1
,
MessageExt
o2
)
{
return
(
int
)
(
o1
.
getQueueOffset
()
-
o2
.
getQueueOffset
());
}
});
for
(
int
j
=
0
;
j
<
msgEachQueue
;
j
++)
{
Assert
.
assertEquals
(
j
,
messageExts
.
get
(
j
).
getQueueOffset
());
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录