问题:
最近交换机更换板卡,网络不稳定,消息丢失严重:pika 向 Rabbit MQ 放置消息,出现connection timeout:
Connection to 10.17.1.226:5672 failed: timeout
原因是,网络状况恶化,pika到 Rabbit MQ 的TCP 连接由于超时而无法建立。
默认情况下,pika的超时时间是0.25s
解决办法:
设置pika的连接socket_time参数超时时间长一些,例如1s:
connection = pika.BlockingConnection(pika.ConnectionParameters(host=
'10.17.1.226',port=
5672,credentials=cred,socket_timeout=
1))
参考
https://sys101.wordpress.com/2016/01/31/python-rabbitmq-pika-client-remote-connection-timeout/
https://sys101.doloveyou.com/year/2015/articles/Python_RabbitMQ_pika_client_remote_connection_timeout.html
pika parameters https://pika.readthedocs.io/en/0.10.0/modules/parameters.html