1 Star 0 Fork 0

小码哥/task_celery

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
RabbitMQ支持不同的语言,对于不同语言有相应的模块,这些模式支持使用开发语言连接RabbitMQ
Python连接RabbitMQ模块有:
  1.pika主流模块
  2.Celery分布式消息队列
  3.Haigha提供了一个简单的使用客户端库来与AMQP代理进行交互的方法

消息持久化
如果当RabbitMQ服务器宕机了,不允许为处理的消息丢失时
  1.需要在声明队列时,声明为持久队列,只是队列持久化,消息未能持久化
    channel.queue_declare(queue='hello',durable=True)

  2.需要在发送端发送消息时声明
    channel.basic_publish(exchange='',
    routing_key='hello', #队列名称
    body='Hello World!', #body消息内容
    properties=pika.BasicProperties(
    delivery_mode = 2, # make message persistent
    #..这里可以添加附带参数,客户的通过回调函数的位置参数prop.参数名获取
    ))
消息处理配置
  对于不同性能的机器,处理消息量大小不同
  判断接收方消息队列里是否有未处理的消息,如果队列里还有1条消息未处理完,将不能接收新的消息
  channel.basic_qos(prefetch_count=1)



发送广播消息
  使用exchange,exchange的类型决定如果发送广播消息,它就是一个转发器
    类型:
      fanout: 所有bind到此exchange的queue都可以接收消息
      direct: 通过routingKey和exchange决定的那个唯一的queue可以接收消息
      topic:所有符合routingKey(此时可以是一个表达式)的routingKey所bind的queue可以接收消息
      headers: 通过headers 来决定把消息发给哪些queue


  fanout纯广播,只要bind到exchange的queue都能收到广播消息
    ☆发送的消息只广播发送一次
    channel.exchange_declare(exchange='log', type='fanout')
    channel.basic_publish(exchange='log',
    routing_key='',
    body=message)
过滤条件设置
To receive all the logs run:
python receive_logs_topic.py "#"

To receive all logs from the facility "kern":
python receive_logs_topic.py "kern.*"

Or if you want to hear only about "critical" logs:
python receive_logs_topic.py "*.critical"

You can create multiple bindings:
python receive_logs_topic.py "kern.*" "*.critical"

And to emit a log with a routing key "kern.critical" type:
python emit_log_topic.py "kern.critical" "A critical kernel error"

发送端
    python topic_producer.py xxx.info         messagexxxx
    python topic_producer.py xxx.warngin   messagexxxx
    python topic_producer.py xxx.error       messagexxxx

接收端
    python topic_consumer.py *.info
    python topic_consumer.py *.warngin
    python topic_consumer.py *.error
    python topic_consumer.py *.*



 实时监控Celery
Flower是一款基于网络的Celery实时监控软件。使用Flower,可以轻松地监视任务进度和历史记录

使用pip来安装Flower:

pip install flower
Flower将运行具有默认端口5555的服务器,可以通过http://localhost:5555访问web控制台
要启动Flower web控制台,需要运行以下命令:

celery -A test_celery flower

空文件

简介

暂无描述 展开 收起
Python
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mark_detail/task_celery.git
git@gitee.com:mark_detail/task_celery.git
mark_detail
task_celery
task_celery
master

搜索帮助