动作电缆在本地订阅,但不在heroku上

时间:2017-01-25 20:07:58

标签: ruby-on-rails heroku redis puma actioncable

我一直在尝试在网上找到的所有东西,但没有任何工作。希望一些新鲜的眼睛会看到这个问题。这是我第一次使用ActionCable,一切都在本地很好用,但是在推送到heroku时。我的日志没有显示任何actioncable订阅,例如我的dev服务器:

[ActionCable] [email@email.com] MsgsChannel is streaming from msg_channel_34

当发送消息时,我确实看到[ActionCable] Broadcasting to msg_channel_34:但它们没有附加,我猜这意味着received方法没有被访问/调用?

我注意到在heroku的日志中它显示Listening on tcp://0.0.0.0:5000在哪里它正在侦听localhost:3000。我应该以某种方式指向我的heroku应用程序吗?

以下是相关配置文件:

Procfile:

web: bundle exec puma -p 5000  ./config.ru  
actioncable: bundle exec puma -p 28080  cable/config.ru  
redis: redis-server  

***感谢下面的评论,我也在努力。仍然没有工作,但我可以看到它正在收听的端口正在改变,让我相信它与配置有关? :

web: bundle exec puma -p $PORT  ./config.ru  
actioncable: bundle exec puma -p $PORT  cable/config.ru  
redis: redis-server  

/cable/config.ru

require ::File.expand_path('../../config/environment',  __FILE__)  
Rails.application.eager_load!

ActionCable.server.config.allowed_request_origins = ["http://localhost:3000"]  
run ActionCable.server 

配置/环境/ development.rb

config.action_cable.allowed_request_origins = ['localhost:3000']
config.action_cable.url = "ws://localhost:3000/cable"

配置/环境/ production.rb

config.web_socket_server_url = "wss://app-name.herokuapp.com/cable" 
  config.action_cable.allowed_request_origins = ['https://app-name.herokuapp.com', 'http://app-name.herokuapp.com']

配置/ cable.yml

local: &local  
  adapter: async
  :url: redis://localhost:6379
  :host: localhost
  :port: 6379
  :timeout: 1
  :inline: true
development: *local  
test: *local


production:
  :url: redis:<%= ENV["REDISTOGO_URL"] %>
  adapter: redis
设置

<%= ENV["REDISTOGO_URL"] %>,通过运行heroku config

确认

的routes.rb

mount ActionCable.server => '/cable'

为什么这适用于开发,但不适用于heroku?我已经读了几个小时,但无法理解。谢谢!!

更新: heroku日志:

2017-01-25T20:32:57.329656+00:00 heroku[web.1]: Starting process with command `bundle exec puma -p 5000  ./config.ru`
2017-01-25T20:32:59.600554+00:00 app[web.1]: Puma starting in single mode...
2017-01-25T20:32:59.600574+00:00 app[web.1]: * Version 3.6.2 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
2017-01-25T20:32:59.600575+00:00 app[web.1]: * Min threads: 0, max threads: 16
2017-01-25T20:32:59.600577+00:00 app[web.1]: * Environment: production
2017-01-25T20:33:02.375128+00:00 app[web.1]: profile controller
2017-01-25T20:33:02.588653+00:00 app[web.1]: Use Ctrl-C to stop
2017-01-25T20:33:02.588446+00:00 app[web.1]: * Listening on tcp://0.0.0.0:5000
2017-01-25T20:33:17.681469+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-01-25T20:33:17.681469+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-01-25T20:33:17.862118+00:00 heroku[web.1]: Process exited with status 137
2017-01-25T20:33:57.501746+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-01-25T20:33:57.501908+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-01-25T20:33:57.630071+00:00 heroku[web.1]: Process exited with status 137
2017-01-25T20:33:57.642753+00:00 heroku[web.1]: State changed from starting to crashed

4 个答案:

答案 0 :(得分:9)

问题是我的主机是heroku应用程序,但请求来自自定义域。

要解决:

heroku config:set RAILS_HOST "http://www.example.com"

然后在production.rb:

config.action_cable.url = "wss://#{ENV['RAILS_HOST']}/cable"

答案 1 :(得分:2)

你的proc文件建议你在端口28080上使用cable / cable.ru运行puma。另外 - file cable / config.ru不应该包含这一行:

ActionCable.server.config.allowed_request_origins = ["http://localhost:3000"]  

您已在config / environment / * .rb

中配置了此项

答案 2 :(得分:1)

您的应用名称字面上是app-name吗?我怀疑不是。这些价值的几率非常好......

config.web_socket_server_url = "wss://app-name.herokuapp.com/cable" 
config.action_cable.allowed_request_origins = ['https://app-name.herokuapp.com', 'http://app-name.herokuapp.com']

需要更新才能使用您要连接的实际公开网址。

答案 3 :(得分:0)

我遇到了同样的问题,并找到了我需要的答案here: redis gem 4+ incompatibility "Specified 'redis' for Action Cable pubsub adapter, but the gem is not loaded"。一旦我将redis降级到3.1.0,就可以正常工作。