celery confirm 机制

在rabbitmq官方文档中提到消息发送到rabbitmq中有消息确认机制,且里面提到的是pika模块实现的。那么celery呢?celery已经用py-amqb模块实现了消息确认机制!
可以参考stackoverflow该网友自问自答的问题:
https://stackoverflow.com/questions/35996065/what-is-the-correct-way-to-confirm-a-publish-in-celery
question
I’m looking at tuning my celery/rabbitmq installation, and I found this article:

http://www.lshift.net/blog/2015/04/30/making-celery-play-nice-with-rabbitmq-and-bigwig/

It mentions doing the setting BROKER_TRANSPORT_OPTIONS = {‘confirm_publish’: True} if you want to guarantee message delivery (which I do). I’m having trouble finding any documentation on this setting for either rabbitmq or celery.

What is the correct way to confirm a publish in celery with rabbitmq? Where is the documentation for said feature?
answer
So to answer my own question: There is currently no documentation.

That said, I dug the source code for most of a morning and found the answer here:

https://github.com/celery/py-amqp/blob/24df1032db4a566e165f736ccb6b4a15cc94bcaa/amqp/channel.py#L1770-L1776

py-amqp is the library that celery ultimately uses (via kombu–two packages deep here folks!). py-amqp reads that setting and has a wait when the confirm_publish option is set. This effectively makes a queuing process synchronous.

最后,我在粘贴下提到的代码:

def basic_publish_confirm(self, *args, **kwargs):
        if not self._confirm_selected:
            self._confirm_selected = True
            self.confirm_select()
        ret = self._basic_publish(*args, **kwargs)
        self.wait(spec.Basic.Ack)
        return ret

之前一直在找celery的publish消息的确认机制都没有头绪,没想到老外居然看源码就找出来了,看来我得好好学习深究源码了,最后,英语是硬伤!

我一直以为是默认设置就可以了,但是怎么验证呢?可以通过rabbitmq的后台web系统查看,如果在配置中添加BROKER_TRANSPORT_OPTIONS = {‘confirm_publish’: True},就会发现,在web系统的overview中Message rates中很明显的看到publisher confirm这个线条跑了,如果不添加该配置,此线条不会跑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值