From 0de4038f8218eee122477c55d149133d706343ca Mon Sep 17 00:00:00 2001 From: zhangjidi2016 <1017543663@qq.com> Date: Fri, 17 Sep 2021 19:45:45 +0800 Subject: [PATCH] [ISSUE #3361]DefaultMQProducer's constructor can call the overloaded constructor. (#3362) Co-authored-by: zhangjidi --- .../client/producer/DefaultMQProducer.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java index 0705935e..50ca82b1 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java @@ -158,22 +158,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { */ public DefaultMQProducer(final String producerGroup, RPCHook rpcHook, boolean enableMsgTrace, final String customizedTraceTopic) { - this.producerGroup = producerGroup; - defaultMQProducerImpl = new DefaultMQProducerImpl(this, rpcHook); - //if client open the message trace feature - if (enableMsgTrace) { - try { - AsyncTraceDispatcher dispatcher = new AsyncTraceDispatcher(producerGroup, TraceDispatcher.Type.PRODUCE, customizedTraceTopic, rpcHook); - dispatcher.setHostProducer(this.defaultMQProducerImpl); - traceDispatcher = dispatcher; - this.defaultMQProducerImpl.registerSendMessageHook( - new SendMessageTraceHookImpl(traceDispatcher)); - this.defaultMQProducerImpl.registerEndTransactionHook( - new EndTransactionTraceHookImpl(traceDispatcher)); - } catch (Throwable e) { - log.error("system mqtrace hook init failed ,maybe can't send msg trace data"); - } - } + this(null, producerGroup, rpcHook, enableMsgTrace, customizedTraceTopic); } /** @@ -251,9 +236,9 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { if (enableMsgTrace) { try { AsyncTraceDispatcher dispatcher = new AsyncTraceDispatcher(producerGroup, TraceDispatcher.Type.PRODUCE, customizedTraceTopic, rpcHook); - dispatcher.setHostProducer(this.getDefaultMQProducerImpl()); + dispatcher.setHostProducer(this.defaultMQProducerImpl); traceDispatcher = dispatcher; - this.getDefaultMQProducerImpl().registerSendMessageHook( + this.defaultMQProducerImpl.registerSendMessageHook( new SendMessageTraceHookImpl(traceDispatcher)); this.defaultMQProducerImpl.registerEndTransactionHook( new EndTransactionTraceHookImpl(traceDispatcher)); -- GitLab