关于RabbitMQ的几个问题

在读如下这篇文章之前,对消息队列尚有几个问题不甚明朗。当然,读完该文后,关于队列的概念就一目了然。

http://rubyamqp.info/articles/working_with_queues/

我在RabbitMQ邮件列表上问了几个问题:

  1. 获取消息时,consume和get方法的区别是什么?
  2. 如何设置消息ack?
  3. 假如消息ack打开了,comsumer是自动发送ACK,还是要手工调用方法发送?
  4. 如何设置消息事务,例如提交和回滚消息?

来自RabbitMQ开发公司的Emile Joubert回答了这几个问题,贴出来共享之。

> * What’s the difference between “consume” and “get” for a consumer?

The one is asynchronous and the other synchronous. When a client uses
“consume” the broker will deliver messages as soon as any are available,
while with “get” the client needs to poll the broker.

> * Where to setup the message acknowledgment?

Clients decide on this via the “no-ack” parameter of the “basic.consume”
or “basic.get” methods.

http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume.no-ack
http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.get.no-ack

> * If message acknowledgment is enabled, will the consumer send the ACK
> automatically, or by a method call?

If the consumer set “no-ack/auto-ack” true then the broker will not
expect acknowledgements from the consumer.
If the consumer set “no-ack/auto-ack” false then the consumer must
acknowledge messages using the basic.ack method:

http://www.rabbitmq.com/amqp-0-9-1-quickref.html#basic.ack

Also see section “2.1.2.1 Message Life-cycle” in the 0.9.1 AMQP
specification for a more detailed description.

> * Any guide for transaction? for example, commit and rollback a transaction.

Transactions are discouraged, but see this for more details:
http://www.rabbitmq.com/semantics.html#tx
http://www.rabbitmq.com/amqp-0-9-1-quickref.html#class.tx

Publisher confirms are recommended instead of transactions:
http://www.rabbitmq.com/extensions.html#publishing

此条目发表在Common分类目录,贴了标签。将固定链接加入收藏夹。