I noticed that invoking QueueControl#removeAllMessages
can return a value less than the number of messages in the queue seen by QueueControl#getMessageCount
. I observed it to be up to 32,768 messages less when I simulated an unresponsive consumer. I tracked this down to prefetch (consumerWindowSize
for Artemis clients) as the cause, which makes sense (and verified that setting prefetch to 0 caused us to result in a message count of 0 afterwards).
If I do removeAllMessages
and I have a client using prefetch, does this ensure all memory on the queue is free-able? Or are those messages that are still "being delivered" held onto by the Artemis broker and hence not able to be freed? If this is the case, is there a way to ensure the broker no longer retains reference to these delivering messages? I am implementing an automated queue purge for unresponsive queue consumers to free up memory in specific circumstances, and want to ensure this stays effective with clients prefetching messages.
Messages which have been dispatched to clients but have not yet been acknowledged will not be removed when executing removeAllMessages
. If those messages were removed then any client acknowledging a message they had received would receive an error.
If you really want to remove all the messages, including messages that have been dispatched to clients then you should execute ActiveMQServerControlImpl#destroyQueue(String, boolean)
and pass true
for the second parameter to remove the attached consumers.