记录一下,

最近在用机器学习打算做一个Rest API, 数据存入mongo,任务采用消息队列,rabbitmq

由于引擎采用python编写,所以WEB也直接打算用python编写了,比较省事。

WEB采用flask,连接rabbitmq使用pika,但是在链接过程中,无论是消费还是生产,只要过了一段时间就会主动断链,

提示:

Connection reset by peer

其实原因很简单,服务端没有收到客户端的心跳包,默认是10秒,但是预计的已经超过10秒还没有发心跳包,所以服务端主动断连了。

解决的办法:

py2的代码:

    def __init__(self,  # pylint: disable=R0913,R0914,R0912
host=_DEFAULT,
port=_DEFAULT,
virtual_host=_DEFAULT,
credentials=_DEFAULT,
channel_max=_DEFAULT,
frame_max=_DEFAULT,
heartbeat=_DEFAULT,
ssl=_DEFAULT,
ssl_options=_DEFAULT,
connection_attempts=_DEFAULT,
retry_delay=_DEFAULT,
socket_timeout=_DEFAULT,
locale=_DEFAULT,
backpressure_detection=_DEFAULT,
blocked_connection_timeout=_DEFAULT,
client_properties=_DEFAULT,
tcp_options=_DEFAULT,
**kwargs):
"""Create a new ConnectionParameters instance. See `Parameters` for
default values. :param str host: Hostname or IP Address to connect to
:param int port: TCP port to connect to
:param str virtual_host: RabbitMQ virtual host to use
:param pika.credentials.Credentials credentials: auth credentials
:param int channel_max: Maximum number of channels to allow
:param int frame_max: The maximum byte size for an AMQP frame
:param int heartbeat: Heartbeat timeout. Max between this value
and server's proposal will be used as the heartbeat timeout. Use 0
to deactivate heartbeats and None to accept server's proposal.
:param bool ssl: Enable SSL
:param dict ssl_options: None or a dict of arguments to be passed to
ssl.wrap_socket
:param int connection_attempts: Maximum number of retry attempts
:param int|float retry_delay: Time to wait in seconds, before the next
:param int|float socket_timeout: Use for high latency networks
:param str locale: Set the locale value
:param bool backpressure_detection: DEPRECATED in favor of
`Connection.Blocked` and `Connection.Unblocked`. See
`Connection.add_on_connection_blocked_callback`.
:param blocked_connection_timeout: If not None,
the value is a non-negative timeout, in seconds, for the
connection to remain blocked (triggered by Connection.Blocked from
broker); if the timeout expires before connection becomes unblocked,
the connection will be torn down, triggering the adapter-specific
mechanism for informing client app about the closed connection (
e.g., on_close_callback or ConnectionClosed exception) with
`reason_code` of `InternalCloseReasons.BLOCKED_CONNECTION_TIMEOUT`.
:type blocked_connection_timeout: None, int, float
:param client_properties: None or dict of client properties used to
override the fields in the default client properties reported to
RabbitMQ via `Connection.StartOk` method.
:param heartbeat_interval: DEPRECATED; use `heartbeat` instead, and
don't pass both
:param tcp_options: None or a dict of TCP options to set for socket
"""

在py3:ConnectionParameters设置heartbeat_interval=0即可。

在py2:ConnectionParameters设置heartbeat=0即可。

python使用pika链接rabbitmq Connection reset by peer 解决办法的更多相关文章

  1. fatal: read error: Connection reset by peer解决办法

    标签(空格分隔): ceph源码安装,git 问题描述: 源码安装ceph,克隆代码时提示如下错误: [root@localhost ~]# git clone git://github.com/ce ...

  2. Loadrunner回放https脚本时出现错误Error -27780 Connection reset by peer解决办法

    录制好的https协议的web脚本,在脚本回放时会出现Error -27780: [GENERAL_MSG_CAT_SSL_ERROR]connect to host "......&quo ...

  3. ssh_exchange_identification: read: Connection reset by peer解决办法

    使用本地终端连接centos服务器,提示ssh_exchange_identification: read: Connection reset by peer $ssh root@10.xxx.xxx ...

  4. ssh_exchange_identification: read: Connection reset by peer 解决思路

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/Jdk_yxs/article/deta ...

  5. 【Mac + ATX基于uiautomator2】使用weditor时,报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

    产生以下原因找到了:是因为启动了appium,两者冲突,不能同时使用. 之前讲过怎么安装u2([Mac安装,ATX基于uiautomator2]之安装步骤)以及使用weditor, 但是经过一段时间, ...

  6. ssh-copy-id to filter out any that...ERROR: Read from socket failed: Connection reset by peer

    ssh-copy-id bigboss1 /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter ...

  7. 【airtest, python】报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')),解决方法如下

    环境及设备 mac, xcode , iphonex 问题 最近出现一个让人费解的问题,airtest 没跑多长时间,服务就断掉,而且总是报“requests.exceptions.Connectio ...

  8. 【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"

    问题描述 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connecti ...

  9. celery使用rabbitmq报错[Errno 104] Connection reset by peer.

    写好celery任务文件,使用celery -A app worker --loglevel=info启动时,报告如下错误: [2019-01-29 01:19:26,680: ERROR/MainP ...

随机推荐

  1. 分享知识-快乐自己:都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事

    都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事 就用下面这段代码在jdk的三个版本运行看了下效果: import java.lang.reflect.Field ...

  2. Django进阶Template篇002 - 模板包含和继承

    包含 {% include %} 允许在模板中包含其他模板的内容. {% include "foo/bar.html" %} {% include template_name %} ...

  3. 解决:actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file ..\..\ccutil\tessdatamanager.cp p, line 50

    在玩tesseract时,发现如下报错: 这个是因为Tesseract-OCR的版本和chi_sim.traindata字库版本不匹配,由于我的Tesseract-OCR是3.02.02,去googl ...

  4. python---迭代器与生成器(一)

    迭代器与生成器 迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式.. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代 ...

  5. 转: OLAP引擎——Kylin介绍

    本文转自:http://blog.csdn.net/yu616568/article/details/48103415 ,如有侵犯,立刻删除.  Kylin是ebay开发的一套OLAP系统,与Mond ...

  6. QGrapicsItem类

    这个类翻译了好久,实在是成员函数太多了,分享出来,希望对大家有用,多多支持哦~~ 详细介绍 QGraphicsItem类是视图框架的一部分,是在一个QGraphicsScene中最基本的图形类,它为绘 ...

  7. php之接口内curl请求其他接口

    今天遇到一个需要写curl的需求,情况是这样的: 同一应用的A系统(购物系统),B系统(答题系统)相互独立,用户数据全部存在于A系统的数据库中, 现在处于B系统的某项操作中,需要在B系统中验证当前请求 ...

  8. [置顶] 【机器学习PAI实践六】金融贷款发放预测

    一.背景 很多农民因为缺乏资金,在每年耕种前会向相关机构申请贷款来购买种地需要的物资,等丰收之后偿还.农业贷款发放问题是一个典型的数据挖掘问题.贷款发放人通过往年的数据,包括贷款人的年收入.种植的作物 ...

  9. 前端基础之jQuery入门 01

    jQuery介绍 jQuery是一个轻量级的.兼容多浏览器的JavaScript库. jQuery使用户能够更方便地处理HTML Document.Events.实现动画效果.方便地进行Ajax交互, ...

  10. typedeifn typename

    1.类型说明typedef 类型说明的格式为: typedef  类型 定义名; 类型说明只定义了一个数据类型的新名字而不是定义一种新的数据类型.定义名表示这个类型的新名字. 例如: 用下面语句定义整 ...