Multiple Servers and Background Jobs

Scott Barrow edited this page Jan 4, 2016 · 5 revisions

WebsocketRails supports synchronization between multiple load balanced server instances and the ability to trigger channel events from within background jobs. In development mode, synchronization allows developers to trigger events directly from the Rails console.

The synchronization is accomplished using Redis to propagate messages out to all active servers. You will need a Redis server running to use this feature.

Enabling Synchronization

To utilize synchronization, you will need to enable it in your initializer file. You can find this option in your config/initializers/websocket_rails.rb initializer

WebsocketRails.setup do |config|
  config.synchronize = true

This is a required configuration in order to have Sidekiq process jobs in a multi-threaded environment

By default, WebsocketRails will attempt to connect to Redis on localhost:6379. If you need to change this, you can set your redis host and port explicitly.

WebsocketRails.setup do |config|
  config.synchronize = true
  config.redis_options = {:host => 'redis-host', :port => '1234'}

That's It

Once synchronization has been enabled, events will automatically propagate to all active server instances. You can trigger channel events from background jobs just like you would anywhere else in your application.

WebsocketRails[:channel_name].trigger :event_name, data_object
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.