记录一下,

最近在用机器学习打算做一个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. GO学习笔记:面向对象--method

    现在假设有这么一个场景,你定义了一个struct叫做长方形,你现在想要计算他的面积,那么按照我们一般的思路应该会用下面的方式来实现: package main import "fmt&quo ...

  2. SpringBoot_09_使用jar包中配置的Bean(starter配置)

    一.前言 二.配置方式 在 META-INF/spring.factories 中声明主配置类,并开启bean的扫描 三.参考资料 1.Understanding auto-configured be ...

  3. validate参数校验和数据回显

    服务端校验 校验理解 项目中,通常使用较多的是前段的校验,比如在页面中js校验.对于安全要求较高的建议在服务端进行校验. 服务端校验: 控制层controller:校验页面请求的参数的合法性.在服务端 ...

  4. 剑指offer--25.二叉树的镜像

    时间限制:1秒 空间限制:32768K 热度指数:238655 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 ...

  5. nginx结合tomcat一起使用

    反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时 ...

  6. Arcgis Add-In开发入门实例

    作为一个本科侧重于应用,工作之后却做了开发的程序员来说,做GIS,开发应该是一门必修课,只是,苦于各种原因吧,做GIS应用的人会开发的很少,做GIS开发的大部分都是计算机出身,痛心疾首啊-- 不好意思 ...

  7. 【vs2013】使用VS2013打包程序

    如何用 VS 2013 打包 程序? 摘自:http://www.zhihu.com/question/25415940 更多请见摘自. 答案就在这里,想要你的exe独立运行在XP中:1.将平台工具集 ...

  8. 【MFC】对话框自带滚动条的使用

    对话框自带滚动条的使用 摘自 http://wenku.baidu.com/link?url=aZe1zgBSBsf9xCYNpcz2fNGljmKxg372OVIGeJ7p6iRCWbbsertS7 ...

  9. dynamic_caast操作符

    dynamic_caast操作符,将基类的指针或引用安全的转换为派生类的指针或引用. 原理: 将一个基类对象指针或引用抛到继承类指针,dynamic_cast会根据基类指针是否真正指向继承类指针来做相 ...

  10. 接口测试基础——第5篇xlrd模块

    读取Excel表格中的内容,不多说,直接上代码: # coding: utf-8 import xlrd # excel路径 excel_path = r'C:\Users\weiming\Deskt ...