芹菜的出版和订阅图书馆
celery_pubsub的Python项目详细描述
基本用法:
importceleryimportcelery_pubsub@celery.taskdefmy_task_1(*args,**kwargs):return"task 1 done"@celery.taskdefmy_task_2(*args,**kwargs):return"task 2 done"# First, let's subscribecelery_pubsub.subscribe('some.topic',my_task_1)celery_pubsub.subscribe('some.topic',my_task_2)# Now, let's publish somethingres=celery_pubsub.publish('some.topic',data='something',value=42)# We can get the results if we want to (and if the tasks returned something)# But in pub/sub, usually, there's no result.print(res.get())# This will get nowhere, as no task subscribed to this topicres=celery_pubsub.publish('nowhere',data='something else',value=23)
高级用法:
通配符可用于主题名:
- *匹配任何一个组
- some.*.test将匹配some.awesome.test,some.random.test 但不是some.pretty.cool.test、elsewhere或here.some.up.test
- some.*将匹配some.test和some.thing,但不会匹配 匹配some或some.testy.test
- #匹配任意数量的组
- some.#.test将匹配some.awesome.test,some.random.test, some.pretty.cool.test但不是elsewhere或here.some.up.test
- some.#将匹配以some.开头的任何内容,例如 some.very.specific.topic.indeed
- #将匹配任何内容
# Let's subscribecelery_pubsub.subscribe('some.*',my_task_1)celery_pubsub.subscribe('some.*.test',my_task_2)celery_pubsub.subscribe('some.#',my_task_3)celery_pubsub.subscribe('#',my_task_4)celery_pubsub.subscribe('some.beep',my_task_5)# it's okay to have more than one task on the same topiccelery_pubsub.subscribe('some.beep',my_task_6)# Let's publishcelery_pubsub.publish('nowhere',4)# task 4 onlycelery_pubsub.publish('some',8)# task 4 onlycelery_pubsub.publish('some.thing',15)# tasks 1, 3 and 4celery_pubsub.publish('some.true.test',16)# tasks 2, 3 and 4celery_pubsub.publish('some.beep',23)# tasks 1, 3, 4, 5 and 6celery_pubsub.publish('some.very.good.test',42)# tasks 3 and 4# And if you want to publish synchronously:celery_pubsub.publish_now('some.very.good.test',42)# tasks 3 and 4# You can unsubscribe toocelery_pubsub.unsubscribe('#',my_task_4)# Now, task 4 will not be called anymorecelery_pubsub.publish('some.very.good.test',42)# task 3 only
更改日志:
- 0.1.9
- 添加了python 3.4、3.5、3.7和pypy的多个分支
- 固定需求的依赖版本。
- 芹菜4.1.0->;4.2.1
- Kombu 4.1.0->;4.2.1
- 台球3.5.0->;3.5.0.4
- 鼻子固定在1.3.7
- 覆盖率固定在4.3.4(已经是4.3.4,但很模糊)
- CODECLIMATE测试报告固定到0.2.3
- 显示下载次数的额外徽章(感谢Pepy)
- 0.1.8
- 修复损坏的pip install celery_pubsub==0.1.7
- 0.1.7
- 已修复PYPI长描述
- 删除了readme.md并修复了readme.rst
- 添加了命令python setup.py test以运行覆盖率为的单元测试
- Pypy支架
- 0.1.5
- python 3支持
- 0.1.1
- 添加自述文件
- 完善的设置
- 不再需要访问芹菜pubsub.pubsub。直接进入芹菜酒吧。
- 测试已移出包
- 为ci添加travis
- 0.1
- 初始版本