Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 芹菜警告“;收到并删除了未知消息“;_Python_Rabbitmq_Celery_Message Queue_Messagebroker - Fatal编程技术网

Python 芹菜警告“;收到并删除了未知消息“;

Python 芹菜警告“;收到并删除了未知消息“;,python,rabbitmq,celery,message-queue,messagebroker,Python,Rabbitmq,Celery,Message Queue,Messagebroker,我在芹菜中设置了一个任务,让它从某个主题交换中“消费”。当我将消息发送到相关交易所时,我在芹菜控制台上收到错误:“收到并删除了未知消息。错误的目的地?!” 我制作了一个单独的项目文件夹来复制这个问题,其中所有内容都称为test something,其结构如下: celery-test/ L celery.py L celeryconfig.py L tasks.py 我已经看到了关于librabbitmq包的各种StackOverflow问题和GitHub问题。这里的解

我在芹菜中设置了一个任务,让它从某个主题交换中“消费”。当我将消息发送到相关交易所时,我在芹菜控制台上收到错误:“收到并删除了未知消息。错误的目的地?!”

我制作了一个单独的项目文件夹来复制这个问题,其中所有内容都称为test something,其结构如下:

celery-test/  
  L celery.py  
  L celeryconfig.py  
  L tasks.py
我已经看到了关于librabbitmq包的各种StackOverflow问题和GitHub问题。这里的解决方案是卸载这个软件包,但我甚至没有安装它,所以我什么也没有安装。发现的一些问题/问题建议了此解决方案:
-
-

我也尝试过使用任务路由设置,因为我假设问题就在这里,但我无法让它工作

如果有人想知道为什么端口关闭了1,那是因为它指向我的docker容器中的rabbitmq,它不能再使用5672了

芹菜

app = Celery('celery_test', include=['celery_test.tasks'])
app.config_from_object('celery_test.celeryconfig')
celeryconfig.py

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'
    }
}
tasks.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()

这可能不是一个真正的答案,而是一个后续行动。但我想我应该让人们知道谁遇到了这个问题。(这篇文章完全是我的解释,因为我对芹菜还不熟悉,你可能应该对此持保留态度。)

所以基本上我认为发生这种情况的原因是芹菜不理解这个信息。芹菜需要大量的标题和其他属性才能理解messesage试图做什么

可以通过反向工程来模拟这些头文件,但我不打算详细介绍,因为有更简单的方法来解决我计划制作的应用程序


如果有人在这方面有更多的经验,请随时纠正我。

这是为2021年受此影响的任何人准备的。我有一个使用芹菜3.1.x的旧服务(我们称之为“遗留”),还有一个最近创建的使用芹菜5.0.x版本的服务(我们称之为“现代”)

在现代的代码库中,使用
芹菜.signature()
方法创建签名,然后调用
apply\u async()
调用遗留中的任务。旧芹菜确实收到了我的消息,但由于以下错误而丢弃了它:

收到并删除了未知消息。目的地错了

我通过在
celeryconfig.py
文件中添加这一行解决了这个问题:

task_protocol = 1
解释如下: