diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java index b348ecb8f09..ba2d1b5f320 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java @@ -21,6 +21,7 @@ import java.net.SocketAddress; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; import org.apache.rocketmq.broker.BrokerController; @@ -370,15 +371,12 @@ protected SendMessageContext buildMsgContext(ChannelHandlerContext ctx, sendMessageContext.setCommercialOwner(owner); Map properties = MessageDecoder.string2messageProperties(requestHeader.getProperties()); - String uniqueKey = properties.get(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX); properties.put(MessageConst.PROPERTY_MSG_REGION, this.brokerController.getBrokerConfig().getRegionId()); properties.put(MessageConst.PROPERTY_TRACE_SWITCH, String.valueOf(this.brokerController.getBrokerConfig().isTraceOn())); requestHeader.setProperties(MessageDecoder.messageProperties2String(properties)); - if (uniqueKey == null) { - uniqueKey = ""; - } - sendMessageContext.setMsgUniqueKey(uniqueKey); + String uniqueKey = properties.get(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX); + sendMessageContext.setMsgUniqueKey(Optional.ofNullable(uniqueKey).orElse("")); if (properties.containsKey(MessageConst.PROPERTY_SHARDING_KEY)) { sendMessageContext.setMsgType(MessageType.Order_Msg);