-
Notifications
You must be signed in to change notification settings - Fork 17
Multiple Servers and Background Jobs
WebsocketRails now supports synchronization between multiple server instances and the ability to trigger channel events from within background jobs. This is accomplished using Redis to propagate messages out to all active servers. You will need a Redis server running to use this feature.
To utilize synchronization, you will need to enable it in your initializer file. You can place this code at the top of your events.rb
initializer, or create a separate initializer file if you prefer.
WebsocketRails.setup do |config|
config.synchronize = true
end
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'}
end
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