From 0499586eb0c78c35099dfe9842d691ed27e791c2 Mon Sep 17 00:00:00 2001 From: Li Zhanhui Date: Tue, 22 May 2018 20:02:41 +0800 Subject: [PATCH] Show client IP only when required --- .../consumer/ConsumerProgressSubCommand.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java index 67a9197c..75296014 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/ConsumerProgressSubCommand.java @@ -64,6 +64,10 @@ public class ConsumerProgressSubCommand implements SubCommand { opt.setRequired(false); options.addOption(opt); + Option optionShowClientIP = new Option("s", "showClientIP", true, "Show Client IP per Queue"); + optionShowClientIP.setRequired(false); + options.addOption(optionShowClientIP); + return options; } @@ -92,13 +96,22 @@ public class ConsumerProgressSubCommand implements SubCommand { try { defaultMQAdminExt.start(); + + boolean showClientIP = commandLine.hasOption('s') + && "true".equalsIgnoreCase(commandLine.getOptionValue('s')); + if (commandLine.hasOption('g')) { String consumerGroup = commandLine.getOptionValue('g').trim(); ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(consumerGroup); List mqList = new LinkedList(); mqList.addAll(consumeStats.getOffsetTable().keySet()); Collections.sort(mqList); - Map messageQueueAllocationResult = getMessageQueueAllocationResult(defaultMQAdminExt, consumerGroup); + + Map messageQueueAllocationResult = null; + if (showClientIP) { + messageQueueAllocationResult = getMessageQueueAllocationResult(defaultMQAdminExt, consumerGroup); + } + System.out.printf("%-32s %-32s %-4s %-20s %-20s %-20s %-20s %s%n", "#Topic", "#Broker Name", @@ -120,7 +133,11 @@ public class ConsumerProgressSubCommand implements SubCommand { } catch (Exception e) { } - String clientIP = messageQueueAllocationResult.get(mq); + String clientIP = null; + if (showClientIP) { + clientIP = messageQueueAllocationResult.get(mq); + } + System.out.printf("%-32s %-32s %-4d %-20d %-20d %-20s %-20d %s%n", UtilAll.frontStringAtLeast(mq.getTopic(), 32), UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), -- GitLab