加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails Faye Apache:将Faye从瘦身转移到乘客

发布时间:2020-12-17 02:06:29 所属栏目:百科 来源:网络整理
导读:使用我们的主要应用程序在Passenger和Faye on Thin上进行部署目前正在进行中.但是我也有一些问题从使用乘客过渡到Faye. 它建议在这里(https://github.com/faye/faye-websocket-ruby)我可以在Passenger Standalone上运行Faye并使用此命令启动所述服务器 passe
使用我们的主要应用程序在Passenger和Faye on Thin上进行部署目前正在进行中.但是我也有一些问题从使用乘客过渡到Faye.

它建议在这里(https://github.com/faye/faye-websocket-ruby)我可以在Passenger Standalone上运行Faye并使用此命令启动所述服务器

passenger start -p 9292

但是,这甚至不能在本地工作.首先它返回此错误,指出它无法找到faye.js

http://localhost:9292/faye?message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fhandshake%22%2C%22version%22%3A%221.0%22%2C%22supportedConnectionTypes%22%3A%5B%22callback-polling%22%5D%2C%22id%22%3A%221%22%7D%5D&jsonp=__jsonp1__

错误就是这个

Failed to load resource: the server responded with a status of 404 (Not Found)

当您将浏览器更改为指定位置时,它会显示

no route matches [GET] "/faye"

看着乘客日志,它似乎首先遇到了这个错误

Started GET "/faye" for 127.0.0.1 at 2014-05-09 10:04:23 -0700

ActionController::RoutingError (No route matches [GET] "/faye"):

然后遇到这个

Started OPTIONS "/faye" for 127.0.0.1 at 2014-05-09 10:04:58 -0700

ActionController::RoutingError (No route matches [OPTIONS] "/faye"):

使用Thin运行时,我使用以下命令启动服务器

bundle exec rackup faye.ru -s thin --daemonize -E production

乘客开始尝试和瘦身之间有一些差异,但最大的一个是faye.ru永远不会运行.我的faye.ru是基本的

require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye',:timeout => 45)
Faye::WebSocket.load_adapter('thin')
run faye_server

把它切换到Passenger,我知道我需要删除第三行…但那又怎么样?当我直接将其添加到我的config.ru文件中时,faye服务器最终接管了整个应用程序,这绝对不是我的目标.我想也许把它放在初始化器中会起作用,但是我遇到了以下错误:

undefined method `run' for main:Object (NoMethodError)

我假设是因为这不是.ru文件而是.rb文件.

无论如何,我发现自己很困惑,我绝对会欣赏任何提示/方向.

编辑:

该网站(http://rubydoc.org/github/jamesotron/faye-rails/frames)声明

If you want to run faye-rails on passenger,make sure you are using passenger 4.0 standalone or passenger 4.0 on nginx 1.4+ for nginx with websocket support. Passenger on apache is not supported. Because passenger uses a multi-process model,you must use the faye redis backend. Add gem 'faye-redis' to your Gemfile and configure your routes like this:

config.middleware.use FayeRails::Middleware,mount: '/faye',:timeout => 25,server: 'passenger',engine: {type: Faye::Redis,host: 'localhost'}

但是我已经尝试将相关代码添加到我的application.rb中,其中我有几个配置命令

module App
  class Application < Rails::Application

但只是在下面添加(我所有其他配置.无论是什么)上面建议的代码导致此错误

uninitialized constant App::Application::FayeRails (NameError)

编辑:

添加了faye-rails gem,因为我是个白痴(见评论).这也需要添加

config.middleware.delete Rack::Lock

因为(控制台输出)

faye-rails can't work when Rack::Lock is enabled,as it will cause
a deadlock on every request.

但是,现在我遇到了这个错误

/Users/WEF6/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- passenger (LoadError)

这必须与我在本文中概述的一些变化相关,正如我上面概述的那样,我在本地成功乘客启动后如何收到错误.现在运行乘客服务器会抛出以下错误

Could not spawn process for group location#default: An error occured while starting up the preloader.
     in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:455)
     in 'string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:566)
     in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
     in 'virtual ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options &)' (SmartSpawner.h:752)
     in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr &,const Passenger::ApplicationPool2::Options &,unsigned int)' (Implementation.cpp:804)

[ 2014-05-09 12:15:15.1055 71107/0x10c9ce000 agents/HelperAgent/RequestHandler.h:2222 ]: [Client 21] Cannot checkout session.
Error page:
cannot load such file -- passenger (LoadError)

解决方法

您必须在gemfile中声明faye-rails gem,包括以下行:

'faye-rails','~> 2.0.0'

更新:

我认为您可以解决机架锁定问题,在您的application.rb中添加以下行

config.middleware.delete Rack::Lock

我希望这可以帮助你.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读