Skip to content

Commit

Permalink
Use properties copies instead of referencing the same map when conver…
Browse files Browse the repository at this point in the history
…ting message
  • Loading branch information
gaoyf committed Dec 7, 2023
1 parent 3509621 commit 63cedfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.rocketmq.common.message;

import java.util.HashMap;
import java.util.Map;

public class MessageAccessor {
Expand Down Expand Up @@ -96,4 +97,10 @@ public static Message cloneMessage(final Message msg) {
return newMsg;
}

public static Map<String, String> deepCopyProperties(Map<String, String> properties) {
if (properties == null) {
return null;
}
return new HashMap<>(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ public MessageExtBrokerInner convertMessage(MessageExt msgExt, boolean needRoll)
MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
msgInner.setBody(msgExt.getBody());
msgInner.setFlag(msgExt.getFlag());
MessageAccessor.setProperties(msgInner, msgExt.getProperties());
MessageAccessor.setProperties(msgInner, MessageAccessor.deepCopyProperties(msgExt.getProperties()));
TopicFilterType topicFilterType = MessageExt.parseTopicFilterType(msgInner.getSysFlag());
long tagsCodeValue =
MessageExtBrokerInner.tagsString2tagsCode(topicFilterType, msgInner.getTags());
Expand All @@ -1146,8 +1146,8 @@ public MessageExtBrokerInner convertMessage(MessageExt msgExt, boolean needRoll)
} else {
msgInner.setTopic(msgInner.getProperty(MessageConst.PROPERTY_REAL_TOPIC));
msgInner.setQueueId(Integer.parseInt(msgInner.getProperty(MessageConst.PROPERTY_REAL_QUEUE_ID)));
// MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_TOPIC);
// MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_QUEUE_ID);
MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_TOPIC);
MessageAccessor.clearProperty(msgInner, MessageConst.PROPERTY_REAL_QUEUE_ID);
}
return msgInner;
}
Expand Down

0 comments on commit 63cedfa

Please sign in to comment.