From 74fd61882760e07f9c38cc76b93acb777992efc9 Mon Sep 17 00:00:00 2001 From: Alexej Timonin Date: Sun, 1 Mar 2026 12:11:02 +0100 Subject: [PATCH 1/2] ARTEMIS-5483: AMQFullSize filter identifier New filter identifier to enable filtering by whole message size. --- .../artemis/api/core/FilterConstants.java | 5 +++++ .../artemis/core/filter/impl/FilterImpl.java | 3 +++ .../artemis/core/filter/impl/FilterTest.java | 19 +++++++++++++++++++ docs/user-manual/filter-expressions.adoc | 4 ++++ 4 files changed, 31 insertions(+) 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..b3c6e257a53 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 header. + */ + 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..8a4b512a108 100644 --- a/docs/user-manual/filter-expressions.adoc +++ b/docs/user-manual/filter-expressions.adoc @@ -55,6 +55,10 @@ AMQSize:: The size of a message in bytes. The value is an integer. +AMQFullSize:: +The whole size of a message in bytes. +The value is a long integer. + Any other identifiers used in core filter expressions will be assumed to be properties of the message. == Property Identifier Constraints From b6986508b2b016b14b0a2df5c353059750bdf82b Mon Sep 17 00:00:00 2001 From: Alexej Timonin Date: Fri, 6 Mar 2026 19:20:20 +0100 Subject: [PATCH 2/2] AMQFullSize docs --- .../apache/activemq/artemis/api/core/FilterConstants.java | 2 +- docs/user-manual/filter-expressions.adoc | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) 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 b3c6e257a53..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 @@ -63,7 +63,7 @@ public final class FilterConstants { public static final SimpleString ACTIVEMQ_SIZE = SimpleString.of("AMQSize"); /** - * Name of the Apache Artemis Message full size header. + * Name of the Apache Artemis Message full size filter property. */ public static final SimpleString ACTIVEMQ_FULL_SIZE = SimpleString.of("AMQFullSize"); diff --git a/docs/user-manual/filter-expressions.adoc b/docs/user-manual/filter-expressions.adoc index 8a4b512a108..c149c228a24 100644 --- a/docs/user-manual/filter-expressions.adoc +++ b/docs/user-manual/filter-expressions.adoc @@ -52,15 +52,14 @@ 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. AMQFullSize:: -The whole size of a message in bytes. +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. -Any other identifiers used in core filter expressions will be assumed to be properties of the message. - == Property Identifier Constraints The JMS and Jakarta Messaging specs state that property identifiers (and therefore the identifiers which are valid for use in a filter expression) are an: