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 · 2288 次点击
    这是一个创建于 2083 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    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   ·   实用小工具   ·   1969 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:15 · PVG 00:15 · LAX 09:15 · JFK 12:15
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com