Class: YAKC::MessageBroadcaster
- Inherits:
-
Object
- Object
- YAKC::MessageBroadcaster
- Defined in:
- lib/yakc/message_broadcaster.rb
Instance Attribute Summary collapse
-
#instrumenter ⇒ Object
Returns the value of attribute instrumenter.
-
#message_class ⇒ Object
Returns the value of attribute message_class.
Instance Method Summary collapse
- #handle(topic, message) ⇒ Object
-
#initialize(instrumenter: FallthroughInstrumenter, message_parser:) ⇒ MessageBroadcaster
constructor
A new instance of MessageBroadcaster.
Constructor Details
#initialize(instrumenter: FallthroughInstrumenter, message_parser:) ⇒ MessageBroadcaster
Returns a new instance of MessageBroadcaster.
5 6 7 8 9 |
# File 'lib/yakc/message_broadcaster.rb', line 5 def initialize( instrumenter: FallthroughInstrumenter, message_parser: ) @message_class = @instrumenter = instrumenter.new raise "MessageBroadcaster must have a valid message class" unless @message_class end |
Instance Attribute Details
#instrumenter ⇒ Object
Returns the value of attribute instrumenter.
3 4 5 |
# File 'lib/yakc/message_broadcaster.rb', line 3 def instrumenter @instrumenter end |
#message_class ⇒ Object
Returns the value of attribute message_class.
3 4 5 |
# File 'lib/yakc/message_broadcaster.rb', line 3 def @message_class end |
Instance Method Details
#handle(topic, message) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yakc/message_broadcaster.rb', line 11 def handle( topic, ) msg = @message_class.new( ) @instrumenter.instrument( msg ) do if msg.broadcastable? # broadcast the specific topic event ActiveSupport::Notifications.instrument broadcast_key( topic, msg.event ), message: msg.payload end end end |