rails作业在使用mqtt的sidekiq错误中断管道中被卡住

xoefb8l8  于 2021-06-08  发布在  Redis
关注(0)|答案(1)|浏览(459)

sidekiq试图处理rails作业时出错。我现在将web应用迁移到google云服务,在那里我设置了redis服务器和代理mqtt。
活动工单如下:

def publish_update
topic = "tournament_team_category/#{@round_match.round.tournament_team_category.id}"
payload = {
  round_match: {
    id: @round_match.id,
    started_at: @round_match.started_at,
    ended_at: @round_match.ended_at,
    first_round_match_team: {
      id: @round_match.first_round_match_team.id,
      goals: @round_match.first_round_match_team.goals
    },
    second_round_match_team: {
      id: @round_match.second_round_match_team.id,
      goals: @round_match.second_round_match_team.goals
    }
  }
}

# TODO: Improve exception manage

begin
  MQTT_CLIENT.connect
  MQTT_CLIENT.publish(topic, payload.to_json, false, 1)
  MQTT_CLIENT.disconnect
rescue MQTT::NotConnectedException => _e
  return nil
rescue MQTT::ProtocolException => _e
  return nil
end
end

sidekiq尝试执行此作业时,服务器会显示以下错误:

2020-10-01 13:22:39 worker[20201001t140958]  2020-10-01T13:22:39.897Z 1 TID-gtixo1hip WARN: Errno::EPIPE: Broken pipe
2020-10-01 13:22:39 worker[20201001t140958]  2020-10-01T13:22:39.897Z 1 TID-gtixo1hip WARN: /app/vendor/bundle/ruby/2.6.0/gems/mqtt-0.5.0/lib/mqtt/client.rb:556:in `write'
2020-10-01 13:22:39 worker[20201001t140958]  /app/vendor/bundle/ruby/2.6.0/gems/mqtt-0.5.0/lib/mqtt/client.rb:556:in `block in send_packet'

mqtt client.rb第556行代码是:


# Send a packet to server

   def send_packet(data)

# Raise exception if we aren't connected

   raise MQTT::NotConnectedException if not connected?

# Only allow one thread to write to socket at a time

   @write_semaphore.synchronize do
   @socket.write(data.to_s)
 end
end

我找不到任何解决办法来解决这个问题,我的工作仍然陷于困境。有人有过这样的问题吗?
谢谢

wpx232ag

wpx232ag1#

看起来您的mqtt客户端使用不是线程安全的,您需要:
https://github.com/mperham/sidekiq/wiki/advanced-options#connection-联营

相关问题