Skip to content

[ISSUE #8784] PrintMessageSubCommand support lmq #8785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.cli.Options;
import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.impl.FindBrokerResult;
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.common.message.MessageExt;
Expand Down Expand Up @@ -97,6 +98,12 @@ public Options buildCommandlineOptions(Options options) {
opt.setRequired(false);
options.addOption(opt);

opt =
new Option("l", "lmqParentTopic", true,
"Lmq parent topic, lmq is used to find the route.");
opt.setRequired(false);
options.addOption(opt);

return options;
}

Expand All @@ -113,11 +120,20 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) t
String subExpression =
!commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim();

String lmqParentTopic =
!commandLine.hasOption('l') ? null : commandLine.getOptionValue('l').trim();

boolean printBody = !commandLine.hasOption('d') || Boolean.parseBoolean(commandLine.getOptionValue('d').trim());

consumer.start();

Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
Set<MessageQueue> mqs;
if (lmqParentTopic != null) {
mqs = consumer.fetchSubscribeMessageQueues(lmqParentTopic);
mqs.forEach(mq -> mq.setTopic(topic));
} else {
mqs = consumer.fetchSubscribeMessageQueues(topic);
}
for (MessageQueue mq : mqs) {
long minOffset = consumer.minOffset(mq);
long maxOffset = consumer.maxOffset(mq);
Expand All @@ -139,6 +155,7 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) t
READQ:
for (long offset = minOffset; offset < maxOffset; ) {
try {
fillBrokerAddrIfNotExist(consumer, mq, lmqParentTopic);
PullResult pullResult = consumer.pull(mq, subExpression, offset, 32);
offset = pullResult.getNextBeginOffset();
switch (pullResult.getPullStatus()) {
Expand Down Expand Up @@ -167,4 +184,17 @@ public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) t
consumer.shutdown();
}
}

public void fillBrokerAddrIfNotExist(DefaultMQPullConsumer defaultMQPullConsumer, MessageQueue messageQueue,
String routeTopic) {

FindBrokerResult findBrokerResult = defaultMQPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl().getmQClientFactory()
.findBrokerAddressInSubscribe(messageQueue.getBrokerName(), 0, false);
if (findBrokerResult == null) {
// use lmq parent topic to fill up broker addr table
defaultMQPullConsumer.getDefaultMQPullConsumerImpl().getRebalanceImpl().getmQClientFactory()
.updateTopicRouteInfoFromNameServer(routeTopic);
}

}
}
Loading