博客已搬家,更好阅读体验, 猛戳 http://www.jack-yin.com/coding/translation/activemq-in-action/1749.html
12.1 Exclusive consumers
12.1 排他性消息消费者
When messages are dispatched from an ActiveMQ broker, they’ll always be in first in,
first out order. But if you have more than one message consumer for a queue in your
application(s), you can’t guarantee that the order in which the messages were dispatched
will be the same order in which your application will consume them. This is
because you never have control over the scheduling of threads used to deliver the
messages on the client side—even if all your message consumers are using the same
connection. Ideally you’d only have one message consumer to ensure ordering of
messages. But you may also need to support failover, to have another instance of your
queue message consumer take over the processing of the queue messages if the first
consumer fails. ActiveMQ can support having multiple message consumers on a
queue, but having only one of them receive the messages from that queue. We’ll discuss
this concept in the following subsection.
ActiveMQ代理总是以先进先出的方式转发消息.但是,如果你程序的一个队列中有多个消息消费者,
你就无法保证程序按照代理发送消息的顺序来处理消息.这是因为在客户端,即使你的消息消费者都使
用同一个连接,你也无法控制用于调度消息发送的线程.理想情况是你只使用一个消费者以保证处理
消息的顺序.但是,你可能还需要支持失效转移,支持在第一个消息消费者失效后,使用队列的另外一个
消息消费者实例来接管第一个小消费者.ActiveMQ支持一个消息队列拥有多个消息消费者,但是仅有
一个消费者会从代理接收消息.我们将在下面的小节中阐述这个概念.
12.1.1 Selecting an exclusive message consumer
12.1.1 选择一个排他的的消息消费者
.........................