- Channel was closed: (406) PRECONDITION_FAILED - inequivalent arg ‘durable’ for exchange ‘dev.alarmMessage.exchange’ in vhost ‘/’: received ‘false’ but current is ‘true’
原因:通道配置与之前不一致导致
2.每一个mq都需要一条线程来启动【亲测,开一个线程启动三个mq失败】
3.启动channel与queue是有顺序的【删除原exchange和queue → 先启动生产者publisher生成exchange和queue → 连接可以发送消息后 → 重启消费者consumer】
4.线程process启动方式,启动mq可能会遇到一个问题:python3可以正常启动,uwsgi启动失败,或者是相反情况。
查找原因:1.本身mq的配置代码有错,2.线程启动在windows下,mac下,linux下启动环境不一样也会导致这种错误出现
下面的是我在用的配置【用uwsgi启动】
from multiprocessing import Manager, Process, Queue
import pika
from iot_core import RabbitMQAsyncPublisher
manager = Manager()
publisher_manager_ls = manager.list()
# RabbitMQAsyncPublisher这个是核心类
class MQPUB(RabbitMQAsyncPublisher):
def publish_message(self):
if self._channel is None or not self._channel.is_open:
return
properties = pika.BasicProperties(self._content_type, delivery_mode=2)
tmp_message_list = publisher_manager_ls
for message in tmp_message_list:
self._channel.basic_publish(self._exchange,
self._routing_key,
message,
properties)
publisher_manager_ls.remove(message)
self._message_number += 1
self._deliveries.append(self._message_number)
self._hlog.debug('Published message:\n%s' % message)
self.schedule_next_message()
调用
msg = str(alarm_id) + "_1"
# mq_old.add_message(msg)
# mq_old_test.add_message(msg)
publisher_manager_ls.append(msg) # 就会发出mq消息