blob: 2f407a3fe4d3c3c0468fc4b28d497c0f2a2ca7f4 [file] [log] [blame]
<div class="wiki-content maincontent"><h3>Scenario</h3>
<ul><li>You send 100 messages to a queue.</li><li>Start consumer A, it receives the message</li><li>You start another consumer B, it doesn't receive any messages.</li><li>You kill A.</li><li>Consumer B receives messages now, why?</li></ul>
<h3>Answer</h3>
<p>This is to do with <link><page ri:content-title="What is the Prefetch Limit For?"></page><link-body>prefetch buffers</link-body></link>.</p>
<p>ActiveMQ will try and deliver a number of messages to each consumer as soon as possible to achieve maximum throughput. That means that each consumer typically has 100-1000 messages in RAM ready to be processed so that there is no latency waiting for another message to arrive under periods of high throughput of messages.</p>
<p>The problem is, if consumer A is set with a prefetch value of &gt;= 100 then it will receive all of the messages before consumer B starts. Then when B starts there are actually no messages available to be dispatched to B (since they are all dispatched to A) until either</p>
<ul><li>new messages are sent to the queue</li><li>consumer A stops or its JVM dies</li></ul>
<p>The solution to this problem is to configure the pre-fetch value to something smaller - such as 1, start the consumers together or publish the messages after the consumers have started.</p>
<p>You can also <link><page ri:content-title="How do I change dispatch policy"></page><link-body>change the dispatch policy</link-body></link> to ensure round robin dispatch.</p>
<p>To help diagnose these kinds of issues, try <link><page ri:content-title="JMX"></page></link> or the <link><page ri:content-title="Web Console"></page></link></p>
<h3>See also</h3>
<ul><li><link><page ri:content-title="How do I change dispatch policy"></page></link></li><li><link><page ri:content-title="JMX"></page></link></li><li><link><page ri:content-title="Web Console"></page></link></li></ul>
</div>