python - 芹菜警告“收到并删除未知消息”
问题描述
我正在 Celery 中设置一项任务,以使其从某个主题交换中“消耗”。当我将消息发送到有问题的交易所时,我收到错误消息:“收到并删除了一条未知消息。错误的目的地?!?” 在芹菜控制台上。
我制作了一个单独的项目文件夹来复制所有内容都称为 test-something 的问题,其结构如下:
celery-test/
L celery.py
L celeryconfig.py
L tasks.py
我已经看到了各种 StackOverflow 问题和 GitHub 问题,涉及到 librabbitmq 包。这里的解决方案是卸载这个包,但我什至没有安装它,所以这让我无处可去。发现一些建议此解决方案的问题/问题:
- https://github.com/celery/celery/issues/3675
- Celery &Rabbitmq:WARNING/MainProcess] 收到并删除了未知消息。错误的目的地?!?- GIT 上的实验
我也尝试过使用任务路由设置,因为我认为问题在于 atm,但我无法让它工作。
对于任何想知道为什么端口关闭 1 的人,那是因为它指向我的 docker 容器中的 rabbitmq,它不能再使用 5672。
芹菜.py
app = Celery('celery_test', include=['celery_test.tasks'])
app.config_from_object('celery_test.celeryconfig')
芹菜配置文件
broker_url = 'amqp://guest:guest@localhost:5673//'
result_backend = 'rpc://'
default_exchange = Exchange('default', type='direct')
test_exchange = Exchange('test_exchange', type='topic')
task_queues = (
Queue('default', default_exchange, routing_key='default'),
Queue('test_queue', test_exchange, routing_key='test123test')
)
task_routes = {
'celery_test.tasks.test_method': {
'queue': 'test_queue'
}
}
任务.py
@app.task
def test_method():
print('test_method')
return 'test_method'
然后是我用来发送消息的文件:send.py
connection = pika.BlockingConnection(pika.URLParameters('amqp://guest:guest@localhost:5673/'))
channel = connection.channel()
exchange = 'test_exchange'
routing_key = 'test123test'
message = 'Testmessage'
channel.exchange_declare(exchange=exchange, exchange_type='topic', durable=True)
channel.basic_publish(exchange=exchange, routing_key=routing_key, body=message)
connection.close()
解决方案
这可能不是真正的答案,而是更多的后续行动。但我想我会让人们知道谁遇到了这个问题。(这篇文章是我的全部解释,因为我是芹菜的新手,你可能应该对此持保留态度。)
所以基本上我认为发生这种情况的原因是因为 Celery 不理解这个信息。Celery 需要大量的标头和其他属性才能理解消息试图做什么。
可以通过对这些标头进行逆向工程来模拟这些标头,但我不打算这样做,因为有更简单的方法可以解决我计划制作的应用程序。
如果有人在这个主题上有更多的经验阅读这篇文章,请随时纠正我。
推荐阅读
- django - 为什么我们要使用 django-webpack-loader?
- react-native - 密钥不存在时的 AsyncStorage.getItem 行为
- google-cloud-dataflow - 任何人都可以将 Google 提供的 PubSub 的元数据文件提供给 BigQuery 模板吗?
- android - 从链接打开安卓应用
- json - 将 JSON 插入 Hadoop
- javascript - 在鼠标按下时,点击事件在反应中被触发
- javascript - 如何在 JavaScript 中以低开销访问两个数组作为关联数组?
- javascript - 在选择选项中变得未定义
- python - 为什么 .cfg 不会被重写,而是创建了新文件?
- python - 用于根据更改日期删除选定目录的 Shell 脚本