Pika发布消息成功,其大小小于10k字节,并且当大小大于10k字节时失败。
错误信息如下:
Error. Connection closed, and the message was never delivered.
Traceback (most recent call last):
File "test_mq.py", line 28, in <module>
ret = test_mq.publish(test_str)
File "rbmq.py", line 146, in publish
ret = self._channel.basic_publish(exchange=self.exc, routing_key=self.rkey, body=body, properties=pika.BasicProperties(delivery_mode=2, ))
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 521, in basic_publish
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 1106, in _rpc
File "build/bdist.linux-x86_64/egg/pika/adapters/blocking_connection.py", line 218, in process_data_events
pika.exceptions.ConnectionClosed
代码如下:
def publish(self, body):
ret = False
try:
ret = self._channel.basic_publish(exchange=self.exc, routing_key=self.rkey, body=body, properties=pika.BasicProperties(delivery_mode=2, ))
except pika.exceptions.ConnectionClosed as exc:
print('Error. Connection closed, and the message was never delivered.')
self._reconnect()
ret = self._channel.basic_publish(exchange=self.exc, routing_key=self.rkey, body=body, properties=pika.BasicProperties(delivery_mode=2, ))
print("Try again ret: ", ret)
except Exception as e:
print ("PikaMQ publish really error ", e)
return ret
test_str_fail = 49143 * 'a'
test_str_ok = 9143 * 'a'
ret = test_mq.publish(test_str_ok) #publish success
ret = test_mq.publish(test_str_fail) #publish fail
答案 0 :(得分:2)
我建议你升级到pika 0.9.14。最新版本修复了几个非常重要的套接字错误;包括导致你的问题的那个。
您可以使用pip升级到0.9.14:
pip install pika --upgrade
这取自尚未完成的changelog for 0.9.14。
Major issue with socket buffer refactor in 0.9.13 (#328) fixes by cooper6581 and Erik Andersson
作为替代方案,如果由于某种原因你无法从0.9.13升级到0.9.14,你可以试用一些替代的RabbitMQ客户端用于Python。
pip install amqp-storm
pip install rabbitpy
pip install amqp
pip install librabbitmq
pip install txamqp
- 在兔子官方网站here上可以获得更全面的鼠兔替代品清单。