擅长:python、mysql、java
<p>您可以尝试将<code>heartbeat</code>添加到您的<code>ConnectionParameters</code>中。这将通过每指定秒发送心跳来创建流量较小的流量。这将锻炼人际关系。一些防火墙或代理程序倾向于抓取空闲连接。即使是RabbitMQ也有空闲连接的超时。在</p>
<pre><code>import pika
# Set the connection parameters to connect to rabbit-server1 on port 5672
# on the / virtual host using the username "guest" and password "guest"
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('rabbit-server1',
5672,
'/',
heartbeat=60,
credentials)
</code></pre>
<p>请参见<a href="https://pika.readthedocs.io/en/stable/modules/parameters.html#pika.connection.ConnectionParameters.heartbeat" rel="nofollow noreferrer">here</a>获取pika文档。在</p>
<p>此外,您应该有适当的代码,以减轻网络断开。这种事总是会发生而且会发生的。因此,来自heartbeat的appart有一些异常处理准备以一种优雅的方式重新打开关闭的连接。在</p>