1. 程式人生 > >rabbitmq在ios中實戰採坑

rabbitmq在ios中實戰採坑

1. rabbitmq在ios中實戰採坑

1.1. 問題

  1. ios使用rabbitmq連線,沒過多久就斷開,並報錯。且用android做相同的步驟並不會報錯,錯誤如下
Received connection: <RMQConnection: 0x600002594080> disconnectedWithError: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}
  1. 之後通過檢視rabbitmq日誌發現,日誌同樣也報了錯誤,如下
{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
[
  {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