Message Dispatching Feautres
Message Cousors 訊息指標(訊息遊標)
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 allows messages to be paged in from storage when space is available (using Store cursors for persistent messages).
從ActiveMQ 5.0.0開始,有一個新的記憶體模型,它允許在空間可用時從儲存中分頁載入訊息(對於持久訊息使用儲存遊標)。
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.
5.0之前的版本在記憶體中儲存了所有可以傳送到活動持久主題訂閱者或佇列的訊息的引用。雖然引用本身並不大,但它確實對等待交付的最大訊息數量施加了限制。
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.
訊息傳遞系統排程持久訊息的一種典型方法是,當客戶端準備使用持久訊息時,將它們分批地從長期儲存中提取出來,使用遊標維護下一個要排程的位置。這是一種健壯且可擴充套件的方法,但對於消費者能夠跟上訊息的生產者的情況,這並不是最有效的方法。
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.
ActiveMQ 5.0採用了一種混合方法,允許訊息直接從生產者傳遞到消費者(在訊息被持久化後),但如果消費者落後,則迴轉使用遊標。
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:
當訊息消費者既活躍又快速——與訊息生產者保持一致速率,訊息被儲存,然後傳遞到與消費者關聯的代理中的分派佇列:
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:
如果消費者在訊息從持久化被掛起之後變得活躍,或者訊息比生產者慢,那麼訊息將從掛起的遊標分批轉到分派佇列中:
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 cursor that 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 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:
記憶體遊標是如何ActiveMQ4.x版本的工作方式:將訊息的引用儲存在記憶體中,並在需要時傳遞給排程佇列。這可能非常快,但也有缺點,不能處理非常慢的消費者或長期不活躍的消費者:
File based Cursor 基於檔案的遊標
The File based Cursor is dervied from the VM Cursor. 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:
基於檔案的遊標是由記憶體遊標衍生出來的。當代理中的記憶體達到極限時,它可以將訊息分頁到磁碟上的臨時檔案。當訊息儲存可能相對較慢,但使用者通常比較快時,可以使用這種型別的遊標。通過緩衝到磁碟,它允許message broker處理來自生產者的訊息突發,而無需求助於慢儲存的分頁:
Paging for Non-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 passed directly to the cursor, so the store based cursor embeds a file based cursor just for these types of messages:
基於儲存的遊標還可以處理非持久訊息,這些訊息不儲存在訊息儲存中。非持久訊息直接傳遞給遊標,因此基於儲存的遊標嵌入了一個基於檔案的遊標,僅用於這些型別的訊息:
Configuring Cursors 配置遊標
By default, Store based cursors are used, but it is possible to configure different cursors depending on the destination.
預設情況下使用基於儲存的遊標,但是可以根據目的地配置不同的遊標。
Topic subscribers Topic訂閱者
For Topics there is a dispatch queue and pending cursor for every subscriber. It's possible to configure different policies for durable subscribers 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 are storeDurableSubscriberCursor, vmDurableCursor and fileDurableSubscriberCursor. The default is the store based cursor
有效的持久訂戶遊標型別包括storeDurableSubscriberCursor、vmDurableCursor和fileDurableSubscriberCursor。預設值是基於儲存的遊標
Queues 佇列
For Queues there is a single dispatch Queue and pending Queue for every destination, so configuration is slightly different:
對於佇列,每個目的地都有一個排程佇列和掛起佇列,因此配置略有不同:
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue="org.apache.>">
<deadLetterStrategy>
<individualDeadLetterStrategy queuePrefix="Test.DLQ."/>
</deadLetterStrategy>
<pendingQueuePolicy>
<vmQueueCursor />
</pendingQueuePolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
Valid Queue cursor types are storeCursor, vmQueueCursor and fileQueueCursor. The default is the store based cursor
有效的佇列遊標型別是storeCursor、vmQueueCursor和fileQueueCursor。預設值是基於儲存的遊標