芹菜为生产者和消费者配置独立的连接 [英] Celery configure separate connection for producer and consumer

查看:195
本文介绍了芹菜为生产者和消费者配置独立的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在heroku上有一个应用程序设置,它使用芹菜来运行后台作业。
芹菜应用程序使用RabbitMQ作为经纪人。
我们使用了heroku的RabbitMQ Bigwig插件作为AMQP消息代理。
这个加载项指定了两个单独的url,一个针对生产者优化,另一个针对消费者优化。
另外,根据RabbitMQ文档,建议为生产者和消费者使用不同的连接。



Celery文档不提供分别指定连接到生产者的方式和消费者。
有没有办法在celery中指定两个不同的代理网址?

解决方案

不幸的是,方法来做到这一点。您可以在 task.apply_async 上显式提供自定义代理连接,但这意味着放弃连接池功能。它可能适合你。

  from kombu import BrokerConnection 
conn = BrokerConnection(hostname =producerbroker)

mytask.apply_async(args,kwargs,connection = conn)

最直接的解决方案可能会有不同生产者和工人的配置文件。


We have an application setup on heroku, which uses celery to run background jobs. The celery app uses RabbitMQ as the broker. We used heroku’s RabbitMQ Bigwig add-on as AMQP message broker. This add-on specifies two separate url one optimized for producer and other optimized for consumer. Also, as per RabbitMQ documentation it is recommended to use separate connections for producer and consumer.

Celery documentation does not provide a ways to specify connections separately to producer and consumer. Is there a way to specify two different broker urls in celery?

解决方案

Unfortunately, there isn't a clean way to do that. You can provide a custom broker connection explicitly on task.apply_async, but that means giving up on the connection pool feature. It might work for you.

from kombu import BrokerConnection
conn = BrokerConnection(hostname="producerbroker")

mytask.apply_async(args, kwargs, connection=conn)

The most straightforward solution is probably to have different config files for producer and worker.

这篇关于芹菜为生产者和消费者配置独立的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆