diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java index 6e903a3ade..6226c6dd40 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java @@ -116,6 +116,10 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. AMQPMessageSymbolSearch.kmpNeedleOf(AMQPMessageSupport.SCHEDULED_DELIVERY_TIME), AMQPMessageSymbolSearch.kmpNeedleOf(AMQPMessageSupport.SCHEDULED_DELIVERY_DELAY)}; + private static final KMPNeedle[] DUPLICATE_ID_NEEDLES = new KMPNeedle[] { + AMQPMessageSymbolSearch.kmpNeedleOf(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString()) + }; + public static final int DEFAULT_MESSAGE_FORMAT = 0; public static final int DEFAULT_MESSAGE_PRIORITY = 4; public static final int MAX_MESSAGE_PRIORITY = 9; @@ -1015,6 +1019,13 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. @Override public final Object getDuplicateProperty() { + + if (applicationProperties == null) { + if (!AMQPMessageSymbolSearch.anyApplicationProperties(getData(), DUPLICATE_ID_NEEDLES)) { + // no need for duplicate-property + return null; + } + } return getObjectProperty(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID); } diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageSymbolSearch.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageSymbolSearch.java index 50876344e2..58dea83743 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageSymbolSearch.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageSymbolSearch.java @@ -52,7 +52,20 @@ final class AMQPMessageSymbolSearch { return KMPNeedle.of(symbol.toString().getBytes(StandardCharsets.US_ASCII)); } - public static boolean anyMessageAnnotations(ReadableBuffer data, KMPNeedle[] needles) { + public static KMPNeedle kmpNeedleOf(String symbol) { + return KMPNeedle.of(symbol.getBytes(StandardCharsets.US_ASCII)); + } + + + public static boolean anyMessageAnnotations(final ReadableBuffer data, final KMPNeedle[] needles) { + return lookupOnSection(MessageAnnotations.class, data, needles); + } + + public static boolean anyApplicationProperties(final ReadableBuffer data, final KMPNeedle[] needles) { + return lookupOnSection(ApplicationProperties.class, data, needles); + } + + private static boolean lookupOnSection(final Class section, final ReadableBuffer data, final KMPNeedle[] needles) { DecoderImpl decoder = TLSEncode.getDecoder(); final int position = data.position(); decoder.setBuffer(data.rewind()); @@ -61,7 +74,7 @@ final class AMQPMessageSymbolSearch { TypeConstructor constructor = decoder.readConstructor(); final Class typeClass = constructor.getTypeClass(); if (MSG_BODY_TYPES.containsKey(typeClass)) { - if (MessageAnnotations.class.equals(typeClass)) { + if (section.equals(typeClass)) { final int start = data.position(); constructor.skipValue(); final int end = data.position();