ActiveMQ - Message Dispatching Feautres - Message Cursors

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 storeDurableSubscriberCursorvmDurableCursor and fileDurableSubscriberCursor. The default is the store based cursor

有效的持久订阅者游标类型包括storeDurableSubscriberCursorvmDurableCursorfileDurableSubscriberCursor。默认值是基于存储的游标

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 storeCursorvmQueueCursor and fileQueueCursor. The default is the store based cursor

有效的队列游标类型是storeCursorvmQueueCursorfileQueueCursor。默认值是基于存储的游标

See Also 另请参阅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值