python - Rabbitmq 消费者和 celery 消费者有什么区别?
问题描述
RabbitMQ 消费者示例
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='logs', exchange_type='fanout')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='logs', queue=queue_name)
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r" % body)
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()
芹菜消费者:
from celery import Celery
app = Celery('tasks', broker='pyamqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
我是新手,如果我错了,请纠正我。
我的问题是这两者之间的主要区别是什么?既等待任务又执行队列中的数据。
我的第二个问题是,我们可以将数据从 rabbitMQ 生产者推送到 rabbitmq-server 并在 Celery 消费者中接收吗?如果是请建议如何?任何参考都会有所帮助。
我试过了,但是 celery 无法理解消息 Use RabbitMQ as procedure 和 Celery as consumer
解决方案
推荐阅读
- powershell - 值不出现在下一行
- javascript - Html5 视频标签 - 仅加载前几秒
- docker - Docker - Ubuntu 20.04 升级后没有路由到主机
- flutter - 如何在颤动中突出显示我的容器的一部分?
- boost-beast - 增强野兽。每个请求三个会话?
- python - 在while循环中附加到列表而不覆盖列表
- elasticsearch - ElasticSearch 中的入口数据
- javascript - 无重复的随机数。初级等级
- flutter - 每次用户导航到页面时淡入一个小部件
- formula - Octave:如何在轴上绘制一个公式,其中包含一系列变量值的曲线范围?