Message Cursors 消息遊标
A common problem in previous versions of ActiveMQ was running out of RAM buffer when using non-persistent messaging.
在之前版本的ActiveMQ版本中,一個普遍的問題是使用非持久化消息傳送時出現RAM緩沖耗盡的情況。
Beginning with ActiveMQ 5.0.0, there is a new memory model that allowsmessages to be paged in from storage when space is available (using Storecursors for persistent messages).
從ActiveMQ 5.0.0版本開始,出現了一種新的記憶體模式,在空間可用時允許消息從儲存設備中以頁為機關進入(對持久化消息使用存儲遊标)。
Releases prior to 5.0 kept references in memory for all the messages thatcould be dispatched to an active Durable Topic Consumer or a Queue. While areference itself is not large, it does impose a limit on the maximum number ofmessages that can be pending delivery.
5.0之前的版本對于可以分發到一個有效的持久性主題消費者或者隊列的所有消息,都在記憶體中保留其引用。雖然一個引用本身并不大,它仍然占用了能夠挂起等待發送的消息數的一點限度。
A typical approach for messaging systems dispatching persistent messagesis to pull them in batches from long term storage when a client is ready toconsume them, using a cursor to maintain the next to dispatch position. This isa robust and very scalable approach, but not the most performant for cases whenthe consumer(s) can keep up with the producer(s) of messages.
消息系統分發持久化消息的一個典型的途徑是,當用戶端準備好消費消息的時候,把它們成批的從長期儲存設備中拉取出來,使用一個遊标來維護下一次要分發的位置。這是一種健壯并且很有伸縮性的方法,但是在消費者(們)與生産者(們)步調一緻的情況下,這不是最高效的方法。
ActiveMQ 5.0 takes a hybrid approach, allowing messages to pass fromproducer to consumer directly (after the messages have been persisted), butswitches back to using cursors if the consumer(s) fall behind.
ActiveMQ 5.0使用一種混合的方法,允許消息直接從生産者傳遞到消費者(當消息已經被持久化了之後),但是當消費者(們)落後之後,切換回使用遊标的模式。
When Message Consumers are both active and fast - keeping up with theMessage Producer(s) - messages are stored and then passed to a dispatch queuein the broker associated with the Consumer:
當消息消費者既活躍,又快速的時候 ——緊随消息生産者的步調—— 消息被存儲之後就被傳遞到代理上跟消費者相關聯的分發隊列裡:
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 dispatchqueue from a pending cursor:
如果一個消費者在消息已經從存儲中挂起之後變的活躍了, 或者它比生産者慢,消息将會以頁為機關,從一個挂起的遊标(pending cursor)進入分發隊列:
Types of Cursor 遊标的類型
The default message cursor type in ActiveMQ 5.0 is Store based. It behaves as above. There are two additional types of cursorthat could be used: VM Cursor and File based Cursor,described below.
ActiveMQ 5.0預設的消息遊标類型是基于存儲的。其工作方式如上所述。還有另外兩種遊标類型可用:虛拟記憶體(VM)遊标和基于檔案的遊标,如下文所述。
VM Cursor 虛拟記憶體遊标
The VM Cursor is how ActiveMQ 4.x works: references to a message are heldin 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 orconsumers that have been inactive for a long time:
虛拟記憶體遊标是ActiveMQ 4.x的工作方式:消息的引用儲存在記憶體中,當需要的時候被傳遞到分發隊列中。這樣做速度很快,但也有缺點,即不能處理非常慢的消費者,或者很長時間不活躍的消費者:
File based Cursor 基于檔案的遊标
The File based Cursor is derived from the VM Cursor. When memory inthe 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 relativelyslow, but consumers are generally fast. By buffering to disk, it allows themessage broker to handle message bursts from producers without resorting topaging in from slow storage:
基于檔案的遊标是從虛拟記憶體遊标衍生而來的。當代理的記憶體達到限度之後,它可以将消息寫入磁盤上的臨時檔案。這種類型的遊标适用的場景是,消息存儲相對要慢,但是消費者要快一些。通過在磁盤上做緩沖,消息代理可以在應對消息爆發的時候,不需要從慢存儲中讀取。
Paging forNon-Persistent Messages 非持久化消息分頁
The store based cursor also handles cursors for non-persistent messages,which are not stored in the message store. Non-persistent messages are passeddirectly to the cursor, so the store based cursor embeds a file based cursorjust for these types of messages:
基于存儲的遊标也可以處理非持久化消息的遊标,這些消息是儲存在消息存儲中的。非持久化消息直接被傳遞給遊标,是以針對這些消息,基于存儲的遊标嵌入了一個基于檔案的遊标:
ConfiguringCursors 配置遊标
By default, Store based cursors are used, but it is possible to configuredifferent cursors depending on the destination.
預設情況下使用的是基于存儲的遊标,但是可以根據目的配置不同的遊标。
Topic subscribers 主題訂閱者
For Topics there is a dispatch queue and pending cursor for everysubscriber. It's possible to configure different policies for durablesubscribers and transient subscribers - e.g:
對所有的主題來說,每一個訂閱者都有一個分發隊列和挂起的遊标。可以針對持久訂閱者和短暫訂閱者分别配置不同的政策,例如:
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic="org.apache.>" producerFlowControl="false" memoryLimit="1mb">
<dispatchPolicy>
<strictOrderDispatchPolicy/>
</dispatchPolicy>
<deadLetterStrategy>
<individualDeadLetterStrategy topicPrefix="Test.DLQ." />
</deadLetterStrategy>
<pendingSubscriberPolicy>
<vmCursor/>
</pendingSubscriberPolicy>
<pendingDurableSubscriberPolicy>
<vmDurableCursor/>
</pendingDurableSubscriberPolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
Valid Subscriber types are vmCursor and fileCursor. . The default is the store based cursor.
有效的訂閱者遊标類型是vmCursor 和fileCursor。預設情況下是基于存儲的遊标。
Valid Durable Subscriber cursor types arevvmDurableCursor and fileDurableSubscriberCursor. The default is the store based cursor
有效的持久訂閱者類遊标類型是vvmDurableCursor 和 fileDurableSubscriberCursor。預設情況下是基于存儲的遊标。
Queues 隊列
For Queues there is a single dispatch Queue and pending Queue for everydestination, so configuration is slightly different:
對于隊列來說,每一個目的地都有一個單獨的分發隊列和挂起隊列,是以配置略微有些不同:
<policyEntry queue="org.apache.>">
<deadLetterStrategy>
<individualDeadLetterStrategyqueuePrefix="Test.DLQ."/>
<pendingQueuePolicy>
<vmQueueCursor/>
</pendingQueuePolicy>
</destinationPolicy>
Valid Queue cursor types are vmQueueCursor and fileQueueCursor. The default is the store based cursor
有效的隊列遊标類型是 vmQueueCursor 和 fileQueueCursor。預設情況下是基于存儲的遊标。