blob: 7651e55ba46da85c9ef65121175f6cc2af5c7d51 [file] [log] [blame]
<div class="wiki-content maincontent"><h2>Message Cursors</h2>
<p>A common problem in previous versions of ActiveMQ was <link><page ri:content-title="My producer blocks"></page><link-body>running out of RAM buffer</link-body></link> when using non-persistent messaging.</p>
<p>Beginning with ActiveMQ 5.0.0, there is a new memory model that allows messages to be paged in from storage when space is available (using Store cursors for persistent messages).</p>
<p>Releases prior to 5.0 kept references in memory for all the messages that could be dispatched to an active Durable Topic Consumer or a Queue. While a reference itself is not large, it does impose a limit on the maximum number of messages that can be pending delivery.</p>
<p>A typical approach for messaging systems dispatching persistent messages is to pull them in batches from long term storage when a client is ready to consume them, using a cursor to maintain the next to dispatch position. This is a robust and very scalable approach, but not the most performant for cases when the consumer(s) can keep up with the producer(s) of messages.</p>
<p>ActiveMQ 5.0 takes a hybrid approach, allowing messages to pass from producer to consumer directly (after the messages have been persisted), but switches back to using cursors if the consumer(s) fall behind.</p>
<p>When Message Consumers are both active and fast - keeping up with the Message Producer(s) - messages are stored and then passed to a dispatch queue in the broker associated with the Consumer: <image ac:align="center"><attachment ri:filename="DispatchFastConsumers.png"></attachment></image><br clear="none">
If a Consumer becomes active after messages are pending from the store for it, or it's slower than the producer, then messages are paged in to the dispatch queue from a pending cursor: <image ac:align="center"><attachment ri:filename="DispatchSlowConsumers.png"></attachment></image></p>
<h3>Types of Cursor</h3>
<p>The default message cursor type in ActiveMQ 5.0&#160;is Store based. &#160;It behaves as above. There are two&#160;additional&#160;types of cursor that could be used: <strong>VM Cursor</strong> and <strong>File based Cursor</strong>, described below.</p>
<h4>VM Cursor</h4>
<p>The VM Cursor is how ActiveMQ 4.x works: references to a message are held in memory, and passed to the dispatch queue when needed. This can be very fast, but also has the downside of not being able to handle very slow consumers or consumers that have been inactive for a long time: <image ac:align="center"><attachment ri:filename="VMCursor.png"></attachment></image></p>
<h4>File based Cursor</h4>
<p>The File based Cursor is dervied from the VM Cursor. &#160;When memory in the broker reaches its limit, it can page messages to temporary files on disk. This type of cursor can be used when the message store might be relatively slow, but consumers are generally fast. By buffering to disk, it allows the message broker to handle message bursts from producers without resorting to paging in from slow storage: <image ac:align="center"><attachment ri:filename="FileCursor.png"></attachment></image></p>
<h4>Paging for Non-Persistent Messages</h4>
<p>The store based cursor also handles cursors for non-persistent messages, which are not stored in the message store. Non-persistent messages are passed directly to the cursor, so the store based cursor embeds a file based cursor just for these types of messages: <image ac:align="center"><attachment ri:filename="NonPersistentMsgs.png"></attachment></image></p>
<h3>Configuring Cursors</h3>
<p>By default, Store based cursors are used, but it is possible to configure different cursors depending on the destination.</p>
<h4>Topic subscribers</h4>
<p>For Topics there is a dispatch queue and pending cursor for every subscriber. &#160;It's possible to configure different policies for durable subscribers and transient subscribers - e.g:</p>
<structured-macro ac:macro-id="8ad8f4ca-d565-4697-9780-4747a4fff7d5" ac:name="code" ac:schema-version="1"><plain-text-body>
&lt;destinationPolicy&gt;
&lt;policyMap&gt;
&lt;policyEntries&gt;
&lt;policyEntry topic="org.apache.&gt;" producerFlowControl="false" memoryLimit="1mb"&gt;
&lt;dispatchPolicy&gt;
&lt;strictOrderDispatchPolicy /&gt;
&lt;/dispatchPolicy&gt;
&lt;deadLetterStrategy&gt;
&lt;individualDeadLetterStrategy topicPrefix="Test.DLQ." /&gt;
&lt;/deadLetterStrategy&gt;
&lt;pendingSubscriberPolicy&gt;
&lt;vmCursor /&gt;
&lt;/pendingSubscriberPolicy&gt;
&lt;pendingDurableSubscriberPolicy&gt;
&lt;vmDurableCursor/&gt;
&lt;/pendingDurableSubscriberPolicy&gt;
&lt;/policyEntry&gt;
&lt;/policyEntries&gt;
&lt;/policyMap&gt;
&lt;/destinationPolicy&gt;
</plain-text-body></structured-macro>
<p>Valid Subscriber types are&#160;<strong><em>vmCursor</em></strong> and <strong><em>fileCursor.</em></strong>&#160;The default is the store based cursor.<br clear="none">
Valid Durable Subscriber cursor types are&#160;<strong><em>storeDurableSubscriberCursor</em></strong>, <strong><em>vmDurableCursor</em></strong> and <strong><em>fileDurableSubscriberCursor.</em></strong>&#160;The default is the store based cursor</p>
<h4>Queues</h4>
<p>For Queues there is a single dispatch Queue and pending Queue for every destination, so configuration is slightly different:</p>
<structured-macro ac:macro-id="1098531a-eb10-4e33-bfbf-bc93b3c6f05b" ac:name="code" ac:schema-version="1"><plain-text-body>
&lt;destinationPolicy&gt;
&lt;policyMap&gt;
&lt;policyEntries&gt;
&lt;policyEntry queue="org.apache.&gt;"&gt;
&lt;deadLetterStrategy&gt;
&lt;individualDeadLetterStrategy queuePrefix="Test.DLQ."/&gt;
&lt;/deadLetterStrategy&gt;
&lt;pendingQueuePolicy&gt;
&lt;vmQueueCursor /&gt;
&lt;/pendingQueuePolicy&gt;
&lt;/policyEntry&gt;
&lt;/policyEntries&gt;
&lt;/policyMap&gt;
&lt;/destinationPolicy&gt;
</plain-text-body></structured-macro>
<p>Valid Queue cursor types are <strong><em>storeCursor</em></strong>, <strong><em>vmQueueCursor</em></strong> and <strong><em>fileQueueCursor.</em></strong>&#160;The default is the store based cursor</p>
<h3>See Also</h3>
<ul><li><link><page ri:content-title="Producer Flow Control"></page></link></li></ul>
</div>