diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java index 0d53b193674..7a52416ede6 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/FilterConstants.java @@ -62,6 +62,11 @@ public final class FilterConstants { */ public static final SimpleString ACTIVEMQ_SIZE = SimpleString.of("AMQSize"); + /** + * Name of the Apache Artemis Message full size filter property. + */ + public static final SimpleString ACTIVEMQ_FULL_SIZE = SimpleString.of("AMQFullSize"); + /** * Name of the Apache Artemis Address header */ diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java index 30bb6c3a54e..3593c955c4c 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/filter/impl/FilterImpl.java @@ -50,6 +50,7 @@ *
  • {@code AMQDurable} - "DURABLE" or "NON_DURABLE" *
  • {@code AMQExpiration} - the expiration of the message *
  • {@code AMQSize} - the encoded size of the full message in bytes + *
  • {@code AMQFullSize} - the whole size of the full message in bytes *
  • {@code AMQUserID} - the user specified ID string (if any) *
  • Any other identifiers that appear in a filter expression represent header values for the message * @@ -177,6 +178,8 @@ private static Object getHeaderFieldValue(final Message msg, final SimpleString return msg.getExpiration(); } else if (FilterConstants.ACTIVEMQ_SIZE.equals(fieldName)) { return msg.getEncodeSize(); + } else if (FilterConstants.ACTIVEMQ_FULL_SIZE.equals(fieldName)) { + return msg.getWholeMessageSize(); } else if (FilterConstants.ACTIVEMQ_ADDRESS.equals(fieldName)) { return msg.getAddress(); } else if (FilterConstants.ACTIVEMQ_GROUP_ID.equals(fieldName)) { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java index f35de2d88cc..3fcfd86527a 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/filter/impl/FilterTest.java @@ -703,6 +703,25 @@ public void testStringLikePunctuation() throws Exception { assertTrue(filter.match(message)); } + @Test + public void testAMQFullSize() throws Exception { + message.setAddress(RandomUtil.randomUUIDSimpleString()); + + long wholeSize = message.getWholeMessageSize(); + + Filter moreThanSmall = FilterImpl.createFilter(SimpleString.of("AMQFullSize > " + (wholeSize - 1))); + Filter lessThanLarge = FilterImpl.createFilter(SimpleString.of("AMQFullSize < " + (wholeSize + 1))); + + Filter lessThanSmall = FilterImpl.createFilter(SimpleString.of("AMQFullSize < " + wholeSize)); + Filter moreThanLarge = FilterImpl.createFilter(SimpleString.of("AMQFullSize > " + wholeSize)); + + assertTrue(moreThanSmall.match(message)); + assertTrue(lessThanLarge.match(message)); + + assertFalse(lessThanSmall.match(message)); + assertFalse(moreThanLarge.match(message)); + } + // TODO: re-implement this. // // @Test diff --git a/docs/user-manual/filter-expressions.adoc b/docs/user-manual/filter-expressions.adoc index a42614ac49a..c149c228a24 100644 --- a/docs/user-manual/filter-expressions.adoc +++ b/docs/user-manual/filter-expressions.adoc @@ -52,10 +52,13 @@ The timestamp of when the message was created. The value is a long integer. AMQSize:: -The size of a message in bytes. +Broker calculated size of a message in bytes. For large messages, the body size may not be fully included. The value is an integer. -Any other identifiers used in core filter expressions will be assumed to be properties of the message. +AMQFullSize:: +Total size of the encoded message in bytes as it would be transmitted over the wire, including headers, properties, and the full body. +Can be used in filters to select messages based on their size. +The value is a long integer. == Property Identifier Constraints