How to split Rails5 web and actioncable server [to make them run as a separate processes]
Asked Answered
D

1

6

Currently i have web and websocket servers running in the same process. My question is how can i start web server without actioncable server but still be able to broadcast messages to clients of actioncable server in separate process?

In Rails5 beta to use action cable i was doing this mount ActionCable.server => '/cable' and simply removing this line i was able to achive exactly what i wanted. But now it's mounted automaticaly...

I have tried '-C' commandline option with no luck.

Despair answered 15/8, 2016 at 10:44 Comment(0)
R
0

For running the action cable as a separate process, we can follow section # 8 Running Standalone Cable Servers in https://guides.rubyonrails.org/v5.0/action_cable_overview.html

step1: remove the below line from config/routes.rb

mount ActionCable.server => "/cable"

step2: add the below line inside config/application.rb

config.action_cable.mount_path = nil

step3: make sure action cable url is set inside config/environments/development.rb and use port 3001 for action cable

config.action_cable.url = "ws://localhost:3001/cable"

step4: add cable/config.ru file with the following content

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

run ActionCable.server

step5: Run the rails server in one terminal tab

rails s

step6: Run the action cable server in another terminal tab

bundle exec puma -p 3001 cable/config.ru

In this way you can run your rails server in 3000 port and action cable server in 3001 port

Rahr answered 22/2, 2023 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.