我正在使用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
当我在本地主机上使用此初始值设定项时,它运行良好。当我把它推到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 和本地主机上崩溃,但 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 上运行,并且经过许多测试,只有当同步设置为 true 时才会出错。
很酷,我一直在搜索,找到了新的示例 http://tgib23.github.io/blog/2014/10/30/deploy-rails-websocket-app-into-heroku/并将我的 websocket 更改为:
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, :user => 'redistogo', :password => 'xxxxxxxxxxxxxxxxxxxx'}
}
end
我登录了heroku,检查了redistogo广告,获取了编码的密码,将其复制到此处的此密码中,如示例所示,我很惊讶-它有效! :)