推荐学习书目
› 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 · Aug 29, 2018 · 3634 views
    This topic created in 2951 days ago, the information mentioned may be changed or developed.

    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.
                             },
                             )
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   863 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
    ♥ Do have faith in what you're doing.