The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer consumes message from the Azure Service Bus queues or topic/subscriptions. The reason for the messages being dead-lettered is that they have reached the maximum delivery count.
The root cause stems from message prefetching. Prefetch is enabled by the Qpid lib by default. When it is turned on, Qpid utilizes a local buffer to prefetch messages from the Azure Service Bus, storing them prior to delivery to the consumer. The issue occurs when Qpid prefetches an excessive number of messages that the consumer is unable to process within the lock duration. Consequently, the consumer is unable to acknowledge or finalize the processing of these messages before the lock expires. Those messages will move to the DLQ when the maximum delivery count is exceeded.
To address this problem, you can either turn off prefetching or modify the prefetch count. Disabling prefetching is achievable by setting jms.prefetchPolicy.all=0 in the JMS client. This configuration allows the JMS client to directly consume messages from the Azure Service Bus, circumventing Qpid's local buffer. Consequently, the consumer can process messages at a suitable pace, guaranteeing smooth processing and issue-free completion.
Why is Prefetch not the default option in Microsoft .NET/Java/Python libs?