代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。