rabbitmq在ios中实战采坑

2019-09-10 18:11:36 浏览数 (1)

1. rabbitmq在ios中实战采坑

1.1. 问题

  1. ios使用rabbitmq连接,没过多久就断开,并报错。且用android做相同的步骤并不会报错,错误如下
代码语言:javascript复制
Received connection: <RMQConnection: 0x600002594080> disconnectedWithError: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}
  1. 之后通过查看rabbitmq日志发现,日志同样也报了错误,如下
代码语言:javascript复制
{handshake_error,starting,0,
    {error,badarg,'connection.start_ok',
        [{rabbit_framing_amqp_0_9_1,encode_method_fields,1,
             [{file,"src/rabbit_framing_amqp_0_9_1.erl"},{line,963}]},
         {rabbit_binary_generator,build_simple_method_frame,3,
             [{file,"src/rabbit_binary_generator.erl"},{line,59}]},

1.2. 解决

  1. 通过修改添加配置解决
  2. 修改rabbitmq.config
代码语言:javascript复制
[
  {rabbit,
   [
     {tcp_listeners, [5672]},
     {heartbeat, 120},{handshake_timeout, 60000},
     {default_vhost, <<"/">>},
     {default_user, <<"user">>},
     {default_pass, <<"bitnami">>},
     {default_permissions, [<<".*">>, <<".*">>, <<".*">>]}
   ]
  },
  {rabbitmq_management,
   [
     {listener, [{port, 15672 }, {ip, "0.0.0.0"}]}
   ]
  }
].
  1. 重点是{heartbeat, 120},{handshake_timeout, 60000},改完重启后发现正常了

1.3. 总结

  1. handshake_timeout 表示对AMQP 0-8/0-9/0-9-1握手的最大时间(在套接字连接和SSL握手之后),以毫秒为间隔 Default: 10000也就是10秒
  2. 事实上在ios连接rabbitmq时,这个握手时间是可能超过10s,为了避免连接断开,设置时间可以长一些

参考 https://www.cnblogs.com/zhen-rh/p/6884297.html

0 人点赞