我的主Rails服务器和单独的Faye服务器(localhost:9292)设置正确以处理消息传递。一切都按预期工作,但我在尝试测试时遇到了问题。
我正在尝试将我的测试设置为每天运行一次的工作人员,如果没有收到消息,我想让应用程序向我发送电子邮件。这是我到目前为止基于Faye's docs
中的信息require 'eventmachine'
require 'faye/websocket'
class PingFayeServerWorker < BaseWorker
def initialize
end
def process
EventMachine.run {
client = Faye::Client.new('http://localhost:9292/faye')
client.set_header('Authorization', 'OAuth abcd-1234')
client.subscribe('/foo') do |message|
puts message.inspect
end
publication = client.publish('/foo', 'text' => 'Hello world')
publication.callback do
puts 'Message received by server!'
end
publication.errback do |error|
puts 'There was a problem: ' + error.message
end
}
end
end