task_controller.rb:
def create
response.headers["Content-Type"] = "text/javascript"
task = Task.create(:blahblah)
if task
data = { :type => 'task', :method => 'create', :object => task }
$redis.publish('message.test', data.to_json)
send_created(task)
else
send_error
end
end
流控制器.rb:
def index
response.headers['Content-Type'] = 'text/event-stream'
redis = Redis.new
redis.psubscribe('message.*') do |on|
on.pmessage do |channel, pattern, data|
response.stream.write("data: #{data}\n\n")
end
end
end
来自同一主机的第二次连接后,应用程序关闭,并且不响应任何请求。日志很清楚,所以我不知道如何解决这个问题。