多个celery如何使用同一个redis做为broker?
曾经有个哥们提了一个这方面的requests,但是最终没有合入的celery中去,所以目前celery没有这个功能,祥见:
- https://github.com/celery/kombu/pull/912
- https://github.com/celery/kombu/issues/853
主要思路是给key加前缀。公司java语言的redis client已经实现了加前缀的功能,这个各个应用就不会出现使用相同key的问题
另外可以通过使用不同的redis的db号来区分,各个应用使用各自的db来实现隔离
Run multiple Celeries on a single Redis
Celery is a great tool for running asynchronous Django tasks, but it can be complicated to configure. One use case I often face is running multiple web applications on the same server, each with their own Celery daemon.
The web apps are typically completely unrelated and may be running different versions of Django, Celery and other packages in separate virtualenvs. For this reason, I also want to keep their Celery backends separated.
There are a quite a few ways to do it:
+ Use a database server (SQL or NoSQL) as Celery's backend, and use separate databases for each app. This is often the default solution, but not the most effective one.
+ Use a message queue server as Celery's backend, and use separate queues for each app. You will need to choose a queue server and install it just for this purpose.
+ Use Redis as Celery's backend, and use separate Redis database numbers for each app. You will need to coordinate so that each app has a unique database number, which can be quite tiresome.
+ Use Redis, and use the same database number but separate queue names for each app. Easy, effective and simple! This is also nice for local development, since you usually already have a Redis server running on your laptop and it needs no configuration.
Using Redis with separate queue names
To use a local Redis server as the Celery backend, all you need in Django's settings.py is this:
BROKER_URL = 'redis://'
CELERY_DEFAULT_QUEUE = 'myapp'
Another web application would then use a different name for the queue:
BROKER_URL = 'redis://'
CELERY_DEFAULT_QUEUE = 'anotherapp'
When you run the Celery daemon processes, each just needs to know which queue it's watching:
manage.py celeryd -Q myapp
manage.py celeryd -Q anotherapp
How is all this stored in the Redis database? You will see a new entry appear:
1) "_kombu.binding.celery"
Under that key, which is a SET, you can see the names of all the configured queues as something like this (use the Redis SMEMBERS command):
1) "celery\x06\x16\x06\x16myapp"
2) "celery\x06\x16\x06\x16anotherapp"
Whenever a new task is created, a Redis key temporarily appears for its queue:
2) "myapp"
As the Celery daemon picks it up, the key is immediately deleted so you won't usually see it unless you stop the daemon.
Note that the queue names are used as a top level Redis keys without any prefixes, so you should choose them wisely.
多个celery如何使用同一个redis做为broker?的更多相关文章
- 使用Redis做分布式
一 为什么使用 Redis 在项目中使用 Redis,主要考虑两个角度:性能和并发.如果只是为了分布式锁这些其他功能,还有其他中间件 Zookpeer 等代替,并非一定要使用 Redis. 性能: 如 ...
- 程序员修神之路--redis做分布式锁可能不那么简单
菜菜哥,复联四上映了,要不要一起去看看? 又想骗我电影票,对不对? 呵呵,想去看了叫我呀 看来你工作不饱和呀 哪有,这两天我刚基于redis写了一个分布式锁,很简单 不管你基于什么做分布式锁,你觉得很 ...
- RabbitMq、ActiveMq、Kafka和Redis做Mq对比
转载自:https://blog.csdn.net/qiqizhiyun/article/details/79848834 一.RabbitMq RabbitMQ是一个Advanced Message ...
- 如何用redis做缓存
redis缓存 在互联网应用中经常需要用redis来缓存热点数据. redis数据在内存,可以保证数据读取的高效,接近每秒数十万次的吞吐量 减少下层持久层数据库读取压力,像mongodb,每秒近千次读 ...
- 使用过redis做异步队列么,你是怎么用的?有什么缺点?
Redis设计主要是用来做缓存的,但是由于它自身的某种特性使得它可以用来做消息队列. 它有几个阻塞式的API可以使用,正是这些阻塞式的API让其有能力做消息队列: 另外,做消息队列的其他特性例如FIF ...
- 使用Redis做MyBatis的二级缓存
使用Redis做MyBatis的二级缓存 通常为了减轻数据库的压力,我们会引入缓存.在Dao查询数据库之前,先去缓存中找是否有要找的数据,如果有则用缓存中的数据即可,就不用查询数据库了. 如果没有才去 ...
- 基于keepalived对redis做高可用配置---转载
关于keepalived的详细介绍,请移步本人相关博客:http://wangfeng7399.blog.51cto.com/3518031/1405785 功能 ip地址 安装软件 主redis 1 ...
- redis做RDB时请求超时case
近期在排查redis做rdb时会有部分请求超时的case.初步推断是我们redisserver上开启了THP(Transparent Huge Pages). 1) Linux本身的 ...
- spring+redis的集成,redis做缓存
1.前言 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.我们都知道,在日常的应用中,数据库瓶颈是最容易出现的 ...
随机推荐
- 关于python logging模块读文档的几个心得
1. logger是分层级的,root是所有logger的祖先. 2. root这个logger在执行logging.warning() 等一系列方法和basicConfig()的时候才会被初始化ha ...
- TCP的三次握手与四次挥手的理解
本文经过借鉴书籍资料.他人博客总结出的知识点,欢迎提问 序列号seq:占4个字节,用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上一个序号,第一个字节的编号由本地随机产生:给字节编上 ...
- java堆栈信息查看,以及JVM性能查看工具-jconsole+jmap
java-core P487 P515 chapter11,主要讲java的异常,里面很多内容收获良多,之前一直没注意过的. 一,Throwable类获得StackTraceElement ,可进行 ...
- GDI+ 实例:绘制验证码
一.概述 一般处理程序 ashx :它没有服务器控件,用response输出什么就是什么. 生成验证码原理:产生随机字符,并将字符生成为图片,同时储存到Session里去,然后验证用户输入的内容是否与 ...
- C语言定义数组时使用枚举作为数组的下标 ——c99功能
部分参考了https://blog.csdn.net/wq3028/article/details/76204690 同时在电脑上进行验证 //温度,电磁阀传感器序号,方便数组定位 typedef e ...
- java开发时,eclipse设置编码
修改eclipse默认工作空间编码方式,General——Workspace——Text file encoding 修改工程编码方式,右击工程——Properties——Resource——Text ...
- AtCoder Beginner Contest 116 C题 【题意:可以在任意区间【L,R】上加1,求通过最少加1次数得到题目给定的区间】】{思维好题}
C - Grand Garden In a flower bed, there are NN flowers, numbered 1,2,......,N1,2,......,N. Initially ...
- Foundation-常用结构体
复习 void test(){ struct Date{ int year; int month; int day; }; struct Date d={2015,5,14}; d.day=6; } ...
- TCP SACK 介绍 转载
一.SACK选项 默认情况下TCP采取的是累积确认机制,这时如果发生了报文乱序到达,接收方只会重复确认最后一个按序到达的报文段,为此发送方的处理只能是重复按序到达接收方的报文段之后的那个报文段,因而它 ...
- spring boot + swagger2
spring boot集成swagger2: swagger2是一个基于restful的开源设计,构建,文档,访问的开源工具集.开发中它的在线可视化文档功能,可以动态生成文档,简化前后对接工作 ...