Description
When a TopicSubscription is configured with a limit on the number of pending messages, it will try to eagerly evict expired messages before dispatching them.
if (!matched.isEmpty() && matched.size() > max) {
removeExpiredMessages();
}
When TopicSubscription#removeExpiredMessages detects an expired message, it will remove it but will increment the counter of dispatched messages as well.
if (node.isExpired()) { matched.remove(); getSubscriptionStatistics().getDispatched().increment(); node.decrementReferenceCount(); if (broker.isExpired(node)) { ((Destination) node.getRegionDestination()).getDestinationStatistics().getExpired().increment(); broker.messageExpired(getContext(), node, this); } break; }
However this has the side effect of affecting the result of getDispatchedQueueSize() and therefore isFull(). These counters will now reflect a new dispatched message that has actually been dropped.
In the worst case scenario slow consumers will no longer receive messages because they are "full" when in fact they have nothing to process.
Am I correct in concluding that expired messages must not count towards the dispatched value?
I have made a quick change, removing the increment, and things look good so far. However I am worried that I may be missing some side effect or specification detail.