V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
qq976739120
V2EX  ›  Python

使用 celery 往指定的 exchange 发送消息

  •  
  •   qq976739120 ·
    qq976739120 · 2018-08-29 15:01:47 +08:00 · 2241 次点击
    这是一个创建于 2038 天前的主题,其中的信息可能已经有所发展或是发生改变。

    celery 文档上的用法好像是声明好 exchange,queue,绑定好之后往队列里发,但是我现在的场景是直接发到 exchange 里就可以,queue 谁来绑定我并不关心,我也不要去做声明用 kombu 自己实现很容易,但是 celery 有什么方法做到吗,我看到的都是直接往 queue 里发.消息队列用的 rmq,类型是 topic,顺便求 flask+celery+rmq 的的最佳实践.以下是我用 kombu 的实现

    def send_as_task( exchange_name, args=(), kwargs={}, routing_key=''):
        exchange = Exchange(name=exchange_name, type='topic', durable=True, auto_delete=False)
        payload = {'args': args, 'kwargs': kwargs}
        with producers[config_use.get_connection()].acquire(block=True) as producer:
            producer.publish(body=payload,
                             serializer='json',
                             compression='bzip2',
                             exchange=exchange,
                             declare=[exchange],
                             routing_key=routing_key,
                             retry=True,
                             retry_policy={
                                 'interval_start': 0,  # First retry immediately,
                                 'interval_step': 2,  # then increase by 2s for every retry.
                                 'interval_max': 30,  # but don't exceed 30s between retries.)
                                 'max_retries': 30,  # give up after 30 tries.
                             },
                             )
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3337 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:25 · PVG 21:25 · LAX 06:25 · JFK 09:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.