From 2fe6dc3034f3d886227c0afbade7ad785e5f9edc Mon Sep 17 00:00:00 2001 From: yuz10 <845238369@qq.com> Date: Wed, 9 Jun 2021 00:57:42 +0800 Subject: [PATCH] #2990 Add message tracing switch in sendMessage command of mqadmin --- .../command/message/SendMessageCommand.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/SendMessageCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/SendMessageCommand.java index e4921c6f..9550742e 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/SendMessageCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/SendMessageCommand.java @@ -68,14 +68,18 @@ public class SendMessageCommand implements SubCommand { opt.setRequired(false); options.addOption(opt); + opt = new Option("m", "msgTraceEnable", true, "Message Trace Enable, Default: false"); + opt.setRequired(false); + options.addOption(opt); + return options; } - private DefaultMQProducer createProducer(RPCHook rpcHook) { + private DefaultMQProducer createProducer(RPCHook rpcHook, boolean msgTraceEnable) { if (this.producer != null) { return producer; } else { - producer = new DefaultMQProducer(rpcHook); + producer = new DefaultMQProducer(null, rpcHook, msgTraceEnable, null); producer.setProducerGroup(Long.toString(System.currentTimeMillis())); return producer; } @@ -112,8 +116,11 @@ public class SendMessageCommand implements SubCommand { } catch (Exception e) { throw new RuntimeException(this.getClass().getSimpleName() + " command failed", e); } - - DefaultMQProducer producer = this.createProducer(rpcHook); + boolean msgTraceEnable = false; + if (commandLine.hasOption('m')) { + msgTraceEnable = Boolean.parseBoolean(commandLine.getOptionValue('m').trim()); + } + DefaultMQProducer producer = this.createProducer(rpcHook, msgTraceEnable); SendResult result; try { producer.start(); @@ -153,4 +160,4 @@ public class SendMessageCommand implements SubCommand { ); } } -} \ No newline at end of file +} -- GitLab