Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何让ActionController::Live streaming与Thin一起工作? 问题:_Ruby On Rails_Ruby_Streaming_Thin_Actioncontroller - Fatal编程技术网

Ruby on rails 如何让ActionController::Live streaming与Thin一起工作? 问题:

Ruby on rails 如何让ActionController::Live streaming与Thin一起工作? 问题:,ruby-on-rails,ruby,streaming,thin,actioncontroller,Ruby On Rails,Ruby,Streaming,Thin,Actioncontroller,您能否将thin与ActionController::Live一起使用来实现服务器端事件(SSE)和长轮询?如果是,怎么做 上下文 虽然标题是重复的,但OP提出了两个问题,把事情搞得一团糟,而这个问题从未得到回答 许多其他帖子建议,如果您通过exec thin start--threaded启动服务器端事件(sse),那么您可以使用thin:而且,Aaron的种子级和Ryan的永久可靠。但是,即使我复制了Railscast示例,我也无法让它与thin一起使用 我试过的 _ _ 运行它 在shel

您能否将
thin
ActionController::Live
一起使用来实现服务器端事件(SSE)和长轮询?如果是,怎么做

上下文 虽然标题是重复的,但OP提出了两个问题,把事情搞得一团糟,而这个问题从未得到回答

许多其他帖子建议,如果您通过
exec thin start--threaded
启动服务器端事件(sse),那么您可以使用
thin
:而且,Aaron的种子级和Ryan的永久可靠。但是,即使我复制了Railscast示例,我也无法让它与
thin
一起使用

我试过的 _

_

运行它 在shell窗口A中:

$ bundle install
Chalcedony[~/Projects/heroku-sample/widget-worker]$ thin start --threaded --trace
Using rack adapter
Thin web server (v1.6.3 codename Protein Powder)
Tracing ON
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
然后在shell窗口B中:

$ curl --no-buffer localhost:3000/widgets/events
回到shell窗口A,我看到请求和响应以1秒的间隔发出(在
0…
1…
2…
之间有1秒的延迟)。那很好:

GET /widgets/events HTTP/1.1
User-Agent: curl/7.37.1
Host: localhost:3000
Accept: */*


HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
X-Request-Id: 95e64eb6-ee21-4e97-a33a-dbf579b3027c
X-Runtime: 0.066925
Connection: close
Server: thin


0... <delay...>


1... <delay...>


2... <delay...>
GET/widgets/events HTTP/1.1
用户代理:curl/7.37.1
主机:localhost:3000
接受:*/*
HTTP/1.1200ok
X-Frame-Options:SAMEORIGIN
X-XSS-Protection:1;模式=块
X-Content-Type-Options:nosniff
缓存控制:没有缓存
内容类型:text/html;字符集=utf-8
X-Request-Id:95e64eb6-ee21-4e97-a33a-dbf579b3027c
X运行时:0.066925
连接:关闭
服务器:瘦
0... 
1.
2.
但在shell窗口B中,打印输出会延迟并立即显示。在Chrome中查看页面时也会发生同样的情况。我是否未能正确配置某些设置

附笔。:
$rake-about
关于应用程序的环境
Ruby版本2.1.4-p265(x86_64-darwin14.0)
RubyGems版本2.2.2
机架版本1.5
Rails版本4.1.8
JavaScript运行时JavaScriptCore
活动记录版本4.1.8
操作包版本4.1.8
操作视图版本4.1.8
操作邮件程序版本4.1.8
主动支持版本4.1.8
中间件Rack::Sendfile,ActionDispatch::Static,#,Rack::Runtime,Rack::MethodOverride,ActionDispatch::RequestId,Rails::Rack::Logger,ActionDispatch::ShowExceptions,ActionDispatch::DebugExceptions,ActionDispatch::Reloader,ActionDispatch::Callbacks,ActiveRecord::Migration::CheckPending,ActiveRecord::ConnectionAdapters::ConnectionManagement,ActiveRecord::QueryCache,ActionDispatch::Cookies,ActionDispatch::Session::CookieStore,ActionDispatch::Flash,ActionDispatch::ParamSpaser,Rack::Head,Rack::ConditionalGet,Rack::ETag
环境发展
数据库适配器postgresql
数据库架构版本20141213003938
P.P.S。
现在你可能会想,“你为什么不像其他人一样使用美洲狮呢?”这是个好问题。现在,我无法在我的机器上制造美洲狮宝石,原因我还没有弄清楚。我在heroku部署的大多数应用程序中都使用了
thin
,所以我对它很满意。如果我不能瘦下来工作,我会在建造彪马上投入更多的精力。

不幸的是,你不能将
AC::Live
thin
一起使用。这是Mark,还有其他选择。

我之前的评论不正确(或者可能是正确的,但最好是出于错误的原因)。好的,仔细阅读一下,我觉得curl上的连接头对于流媒体事件不应该是
close
。您所描述的效果就像它根本不是流式传输,而是等待所有数据传输完毕,然后刷新。我没有答案,但也许这会有帮助。我急切地等待着有更多经验的人!答案很简单。把宝石“薄”换成宝石“彪马”等等。
# ----------------------------------------------------------------
# Gemfile
source 'https://rubygems.org'

gem 'rails', '4.1.8'
gem 'pg'
... snip ...
gem 'thin'
$ bundle install
Chalcedony[~/Projects/heroku-sample/widget-worker]$ thin start --threaded --trace
Using rack adapter
Thin web server (v1.6.3 codename Protein Powder)
Tracing ON
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop
$ curl --no-buffer localhost:3000/widgets/events
GET /widgets/events HTTP/1.1
User-Agent: curl/7.37.1
Host: localhost:3000
Accept: */*


HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
X-Request-Id: 95e64eb6-ee21-4e97-a33a-dbf579b3027c
X-Runtime: 0.066925
Connection: close
Server: thin


0... <delay...>


1... <delay...>


2... <delay...>
$ rake about
About your application's environment
Ruby version              2.1.4-p265 (x86_64-darwin14.0)
RubyGems version          2.2.2
Rack version              1.5
Rails version             4.1.8
JavaScript Runtime        JavaScriptCore
Active Record version     4.1.8
Action Pack version       4.1.8
Action View version       4.1.8
Action Mailer version     4.1.8
Active Support version    4.1.8
Middleware                Rack::Sendfile, ActionDispatch::Static, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fb0cb4ae1a0>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Environment               development
Database adapter          postgresql
Database schema version   20141213003938