【发布时间】:2021-02-25 15:12:24
【问题描述】:
我使用 Python 和 pika 开发了一个消费者。
我与本地 RabbitMq 的连接运行良好,但当我尝试使用我的公司环境时,我遇到了连接问题。
直接连接我本地的 RabbitMq 我使用它并且效果很好:
1)channel.queue_declare(queue='massive_queue')
为了连接集群,我尝试了我的第一种方法,但出现了这个错误:
pika.exceptions.ChannelClosedByBroker: (406, "PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'partner-portal_new-batch-process-file' in vhost '/': received 'false' but current is 'true'")
还有这些:
它很耐用,我用过:2)channel.queue_declare(queue='massive_queue', durable=True)
并收到此错误:
pika.exceptions.ChannelClosedByBroker: (406, "PRECONDITION_FAILED - inequivalent arg 'x-queue-type' for queue 'partner-portal_new-batch-process-file' in vhost '/': received none but current is the value 'classic' of type 'longstr'")
现在我尝试使用参数:3) channel.queue_declare(queue='massive_queue', durable=True, arguments='{"x-queue-type"="classic"}')
我收到了这个错误:
File "../scripts/consumer_new_batch.py", line 16, in <module>
channel.queue_declare(queue='massive_queue', durable=True, arguments='{"x-queue-type"="classic"}')
File "/usr/local/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 2497, in queue_declare
self._impl.queue_declare(
File "/usr/local/lib/python3.8/site-packages/pika/channel.py", line 825, in queue_declare
return self._rpc(
File "/usr/local/lib/python3.8/site-packages/pika/channel.py", line 1348, in _rpc
self._send_method(method)
File "/usr/local/lib/python3.8/site-packages/pika/channel.py", line 1405, in _send_method
self.connection._send_method(self.channel_number, method, content)
File "/usr/local/lib/python3.8/site-packages/pika/connection.py", line 2234, in _send_method
self._send_frame(frame.Method(channel_number, method))
File "/usr/local/lib/python3.8/site-packages/pika/connection.py", line 2219, in _send_frame
marshaled_frame = frame_value.marshal()
File "/usr/local/lib/python3.8/site-packages/pika/frame.py", line 73, in marshal
pieces = self.method.encode()
File "/usr/local/lib/python3.8/site-packages/pika/spec.py", line 1019, in encode
data.encode_table(pieces, self.arguments)
File "/usr/local/lib/python3.8/site-packages/pika/data.py", line 90, in encode_table
for (key, value) in table.items():
AttributeError: 'str' object has no attribute 'items'
【问题讨论】:
-
我更改了参数并且它有效。