Rails 4,实时流媒体,保持打开状态,阻止请求 [英] Rails 4, Live Streaming, stays open, blocking requests
问题描述
我正在尝试使用Rails 4 Live Streaming组件.一切正常,除了似乎流保持打开并阻止新请求.
I'm trying to use Rails 4 Live Streaming component. It all works except that it seems like the stream stays open and blocks new request.
在关闭或单击应用程序中的新链接时,如何确保连接正确关闭?
How can I ensure that the connection close down properly when closing down or clicking on a new link within the application?
这是我的现场活动控制器.
This is my live event controller.
def events
response.headers["Content-Type"] = "text/event-stream"
redis = Redis.new
redis.psubscribe("participants.*") do |on|
on.pmessage do |pattern, event, data|
response.stream.write("event: #{event}\n")
response.stream.write("data: #{data}\n\n")
end
end
rescue IOError
ensure
redis.quit
response.stream.close
end
数据库配置
production:
adapter: postgresql
encoding: unicode
database: ************
pool: 1000
username: ************
password: ************
timeout: 5000
我在使用postgresql 9.2.x的Ubuntu 10.04上将puma用作独立的Web服务器(我没有笨重的静态文件需要nginx提供服务).
I'm using puma as standalone webserver (i don't have heavy static files that need to be served by nginx) on Ubuntu 10.04 with postgresql 9.2.x.
推荐答案
您必须更改开发环境设置才能启用此功能.
You have to change the development environment settings to enable this feature.
在您的config/environments/development.rb中添加或更改它:
Add or change this in your config/environments/development.rb:
config.cache_classes = true
config.eager_load = true
请参见 http://railscasts.com/episodes/401-actioncontroller-live ?view = asciicast
这篇关于Rails 4,实时流媒体,保持打开状态,阻止请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!