-
Notifications
You must be signed in to change notification settings - Fork 151
Write custom broadcasters
Kris Leech edited this page Feb 26, 2015
·
2 revisions
When an event is broadcast to a listener it is done so via an adapter which can choose how to broadcast that event. The default broadcaster simply does listener.public_send(event_name, *args)
.
Example broadcaster gems include LoggerBroadcaster, Wisper::Celluloid and Wisper::Sidekiq
- First create a new gem:
bundle gem wisper-thingy_broadcaster
- Add your broadcaster class which has a method
broadcast
.
module Wisper
module Thingy
class ThingyBroadcaster
def broadcast(subscriber, publisher, event, *args)
# ...
end
end
end
end
That's it.
You can then use your broadcaster as such:
Wisper.configure do |config|
config.broadcaster(:thingy, Thingy::ThingyBroadcaster.new)
end
Wisper.subscribe(MyListener.new, broadcaster: :thingy)
You might also want to have the broadcaster self register itself with Wisper.configuration
, see existing broadcasters for an example.
Need to ask a question? Please ask on StackOverflow tagging the question with wisper.
Found a bug? Please report it on the Issue tracker.