【发布时间】:2015-02-03 05:35:15
【问题描述】:
我有一个启动 xmpp4r 客户端的初始化程序。当我将 puma 服务器作为常规进程运行时,它工作正常。但是当我将 puma 作为守护程序(-d 选项)启动时,它会工作几秒钟并与 xmpp 服务器断开连接。我有单独的线程来处理重新连接,但是当 puma 是守护进程时它不起作用。
def init_reconnection_timer
timers = Timers::Group.new
periodic_timer = timers.every(5) do
if @client.is_disconnected?
begin
Rails.logger.info "XmppConnector ##### reconnecting to #{APP_CONFIG['broker_address']} ..."
connect
Rails.logger.info "XmppConnector ##### connected!"
presence
rescue
end
end
end
Thread.new do
loop do
timers.wait
end
end
end
当 puma 是守护进程时,我从日志中的这段代码中一无所获。 在rails应用程序启动后,它会运行几秒钟,接收消息,iqs,像往常一样没有错误。然后默默断开。这是我的类的构造函数:
class XmppConnector
include Singleton
def initialize
@jid = Jabber::JID::new(APP_CONFIG['broker_username'] + '@' + APP_CONFIG['broker_address'])
@jid.resource='rails'
@client = Jabber::Client::new(@jid)
connect
init_presence_callback
init_message_callback
init_iq_callback
init_reconnection_timer
init_subscription_requests
presence
@protocol_interface = RemoteInterface.new
Rails.logger.info "XmppConnector ##### initialized"
end
但是当 puma 在没有 -d 选项的情况下运行时 - 完全没有问题。在开发和生产中,我的工作站和服务器也是如此。 红宝石 2.0.0 puma 2.9.2 最小线程:0,最大线程:16 轨道 4.2.0beta4
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 xmpp puma xmpp4r