websocket-rails在Heroku上启用同步失败

时间:2014-12-04 20:20:57

标签: ruby-on-rails heroku websocket redis sidekiq

我使用的是Websocket-rails,sidekiq,redis,backbone。

#config/initializers/websocket_rails.rb
WebsocketRails.setup do |config|
  config.standalone = false
  config.synchronize = true  # <= problem
  uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://127.0.0.1")
  config.redis_options = {:host => uri.host, :port => uri.port || 6379}
end

当我在localhost上使用此初始化程序时,它运行良好。当我把它推到heroku时:

$ heroku ps
=== web (1X): `bundle exec rails server -p $PORT`
web.1: crashed 2014/12/04 20:40:35 (~ 28m ago)

如果我创建config.synchronize = false,它不会在heroku和localhost上崩溃,但是websockets不再起作用。

其他信息:

#config/initializers/redis.rb
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://127.0.0.1")
$redis = Redis.new(:host => uri.host, :port => uri.port || 6379, :password => uri.password, :driver => :hiredis)

#config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
  config.redis = {driver: :hiredis}
end

#config/events.rb  -> clear (this file not exist)


#app/assets/javascripts/application.js
...
//= require websocket_rails/main
//= require_tree .
var dispatcher = new WebSocketRails(window.document.location.host + '/websocket');
var channel = dispatcher.subscribe('channel_name');

尝试了我在stackOverflow,google上找到的所有内容。没有尝试让它独立。 有什么建议?我只需要以某种方式使这个websockets在heroku上工作,并且通过许多测试,只有当synchronize设置为true时才会出错。

1 个答案:

答案 0 :(得分:2)

很酷,我一直在搜索,找到新的例子http://tgib23.github.io/blog/2014/10/30/deploy-rails-websocket-app-into-heroku/并将我的websocket改为:

配置/初始化/ websocket_rails.rb

WebsocketRails.setup do |config|
  config.standalone = false
  config.synchronize = true  # <= problem
  uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://127.0.0.1")
  config.redis_options = {:host => uri.host, :port => uri.port || 6379, :user => 'redistogo', :password => 'xxxxxxxxxxxxxxxxxxxx'}
}
end

我登录了heroku,检查了redistogo广告,接受了编码密码​​,在此处将其复制到此密码,例如我很惊讶 - 它有效! :)