记录一下,

最近在用机器学习打算做一个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. RabbitMQ Consumer获取消息的两种方式(poll,subscribe)解析

    以下转自:http://blog.csdn.net/yangbutao/article/details/10395599 rabbitMQ中consumer通过建立到queue的连接,创建channe ...

  2. C++纯虚函数和抽象类的一些要点

    1. 纯虚函数是在其被声明的类中不被实现的函数. 2. 定义了纯虚函数的类是抽象类,可以用来生命变量,但不能用来构造实例. 3. 基类中定义了纯虚函数,派生类要么定义这个纯虚函数,要么重复声明一次这个 ...

  3. PHP中的定界符

    因为PHP是一个Web编程语言,在编程过程中难免会遇到用echo来输出大段的html和javascript脚本的情况,如果用传统的输出方法——按字符串输出的话,肯定要有大量的转义符来对字符串中的引号等 ...

  4. 亲测安装nginx1.8.1 日期2016年3月16日

    1.安装nginx tar zxvf nginx-1.8.1.tar.gz cd nginx-1.8.1 ./configure make make install /usr/local/nginx/ ...

  5. asp.net获取URL和IP地址

    (转自:http://www.cnblogs.com/JuneZhang/archive/2010/11/26/1888863.html) HttpContext.Current.Request.Ur ...

  6. Node.js/Python爬取网上漫画

    某个周日晚上偶然发现了<火星异种>这部漫画,便在网上在线看了起来.在看的过程中图片加载很慢,而且有时候还不小心点到广告,大大延缓了我看的进度.后来想到能不能把先把漫画全部抓取到本地再去看. ...

  7. js区分字符串和数字,有时候需要将字符串转换成数字

    js区分字符串和数字,有时候需要将字符串转换成数字 :parseInt

  8. Android系统自带分享功能的实现(可同时分享文字和图片)

     /** * 分享功能 * * @param context * 上下文 * @param activityTitle * Activity的名字 * @param msgTitle * 消息标题 ...

  9. Dojo Chart之常用统计图

    很多做web的都知道,在很多web系统中会涉及到一些统计图,例如饼状图,柱状图.趋势图.以及叠加图等.提到这儿,做web的都很熟悉的,jquery的highcharts就能搞定所有的涉及到统计图的功能 ...

  10. 深度学习(六十五)移动端网络MobileNets