diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java index 5fb5a7d91c..4e562129bf 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java @@ -847,9 +847,11 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { Filter filter = FilterImpl.createFilter(filterStr); List> messages = new ArrayList<>(); queue.flushExecutor(); + final int limit = addressSettingsRepository.getMatch(queue.getAddress().toString()).getManagementBrowsePageSize(); + int count = 0; try (LinkedListIterator iterator = queue.browserIterator()) { try { - while (iterator.hasNext()) { + while (iterator.hasNext() && count++ < limit) { MessageReference ref = iterator.next(); if (filter == null || filter.match(ref.getMessage())) { Message message = ref.getMessage(); @@ -983,9 +985,11 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { if (filter == null && groupByProperty == null) { result.put(null, getMessageCount()); } else { + final int limit = addressSettingsRepository.getMatch(queue.getAddress().toString()).getManagementBrowsePageSize(); + int count = 0; try (LinkedListIterator iterator = queue.browserIterator()) { try { - while (iterator.hasNext()) { + while (iterator.hasNext() && count++ < limit) { Message message = iterator.next().getMessage(); internalComputeMessage(result, filter, groupByProperty, message); } @@ -1593,14 +1597,14 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { clearIO(); try { - int pageSize = addressSettingsRepository.getMatch(queue.getName().toString()).getManagementBrowsePageSize(); + int limit = addressSettingsRepository.getMatch(queue.getAddress().toString()).getManagementBrowsePageSize(); int currentPageSize = 0; ArrayList c = new ArrayList<>(); Filter thefilter = FilterImpl.createFilter(filter); queue.flushExecutor(); try (LinkedListIterator iterator = queue.browserIterator()) { try { - while (iterator.hasNext() && currentPageSize++ < pageSize) { + while (iterator.hasNext() && currentPageSize++ < limit) { MessageReference ref = iterator.next(); if (thefilter == null || thefilter.match(ref.getMessage())) { c.add(OpenTypeSupport.convert(ref)); diff --git a/docs/user-manual/en/address-model.md b/docs/user-manual/en/address-model.md index df45624263..f58033c4c1 100644 --- a/docs/user-manual/en/address-model.md +++ b/docs/user-manual/en/address-model.md @@ -922,8 +922,8 @@ config reload, by delete policy: `OFF` or `FORCE`. Default is `OFF`. Read more about [configuration reload](config-reload.md). `management-browse-page-size` is the number of messages a management resource -can browse. This is relevant for the "browse" management method exposed on the -queue control. Default is `200`. +can browse. This is relevant for the `browse, list and count-with-filter` management +methods exposed on the queue control. Default is `200`. `default-purge-on-no-consumers` defines a queue's default `purge-on-no-consumers` setting if none is provided on the queue itself. diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java index 3fbe5e9f1c..b04b845e49 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlTest.java @@ -3331,6 +3331,40 @@ public class QueueControlTest extends ManagementTestBase { Assert.assertEquals(new String(body), "theBody"); } + @Test + public void testBrowseLimitOnListBrowseAndFilteredCount() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString queue = RandomUtil.randomSimpleString(); + + AddressSettings addressSettings = new AddressSettings().setManagementBrowsePageSize(5); + server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings); + + session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable)); + + ClientProducer producer = session.createProducer(address); + for (int i = 0; i < 10; i++) { + producer.send(session.createMessage(true)); + } + producer.close(); + + QueueControl queueControl = createManagementControl(address, queue); + + + // no filter, delegates to count metric + Wait.assertEquals(10, queueControl::getMessageCount); + + assertEquals(5, queueControl.browse().length); + assertEquals(5, queueControl.listMessages("").length); + + JsonArray array = JsonUtil.readJsonArray(queueControl.listMessagesAsJSON("")); + assertEquals(5, array.size()); + + // filer could match all + assertEquals(5, queueControl.countMessages("AMQSize > 0")); + + session.deleteQueue(queue); + } + @Test public void testResetGroups() throws Exception { SimpleString address = RandomUtil.randomSimpleString();