Broadcaster

Gem Version Build Status Coverage Status Code Climate Dependency Status

Broadcasting based on Redis PubSub

Installation

Add this line to your application's Gemfile:

gem 'broadcaster'

And then execute:

$ bundle

Or install it yourself as:

$ gem install broadcaster

Usage

broadcaster = Broadcaster.new

subscription_id = broadcaster.subscribe 'channel_1' do |message|
  puts message
end

broadcaster.publish 'channel_1', 'text'
broadcaster.publish 'channel_1', 1
broadcaster.publish 'channel_1', key: 'value'

broadcaster.unsubscribe subscription_id
broadcaster.unsubscribe_all

Global configuration

Broadcaster.configure do |config|
  config.logger = Logger.new '/file.log'
  config.redis_settings = 'redis://host_name:6379'
  # or
  config.redis_client = Redic::Sentinels
  config.redis_settings = hosts: [sentinel_1, sentinel_2], master_name: 'mymaster'
end

Options

options = {
  id: 'my_app',                             # Shared broadcaster for multiple processes
  redis_settings: 'redis://host_name:6379', # Custom redis connection
  logger: Logger.new('/file.log')           # Custom logger
  # or
  redis_client: Redic::Sentinels,
  redis_settings: hosts: [sentinel_1, sentinel_2], master_name: 'mymaster'
}

Broadcaster.new options

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/broadcaster.

License

The gem is available as open source under the terms of the MIT License.