Python Pika basic_发布大型邮件时出现发布错误

Python Pika basic_发布大型邮件时出现发布错误,python,rabbitmq,pika,Python,Rabbitmq,Pika,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 1

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

我建议您升级到pika 0.9.14。最新版本修复了几个相当严重的套接字错误;包括引起你问题的那个

您可以使用pip升级到0.9.14:

pip安装pika——升级

这是从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,可以尝试Python的一些替代RabbitMQ客户端

  • -->code>pip安装amqp storm
  • -->code>pip安装rabbitpy
  • -->code>pip安装amqp
  • --
    pip安装librabbitmq
  • -->code>pip安装txamqp

--在RabbitMQ官方网站上提供了更全面的pika替代品列表。

感谢您提供的可行替代品列表。我想补充一点。当然,这并不是一个全面的列表。我主要是想给他提供一些类似皮卡的替代品,以防他无法使用。