Module: RMessage::Subscriber
- Defined in:
- lib/rmessage/subscriber.rb
Overview
Utility functions to allow setting up and parsing messages received from Redis publishers.
Instance Attribute Summary collapse
-
#channel ⇒ String, ...
readonly
The channel to subscribe to.
-
#events ⇒ Hash
readonly
A map of event labels to classes.
Instance Method Summary collapse
-
#setup_subscription(channel: @channel, auto_parse: false, logger: nil, connection: nil, connection_index: 0, &_) ⇒ Object
Setup a subscription to a specific Redis channel.
Instance Attribute Details
#channel ⇒ String, ... (readonly)
Returns the channel to subscribe to.
7 8 9 |
# File 'lib/rmessage/subscriber.rb', line 7 def channel @channel end |
#events ⇒ Hash (readonly)
Returns a map of event labels to classes.
11 12 13 |
# File 'lib/rmessage/subscriber.rb', line 11 def events @events end |
Instance Method Details
#setup_subscription(channel: @channel, auto_parse: false, logger: nil, connection: nil, connection_index: 0, &_) ⇒ Object
Setup a subscription to a specific Redis channel
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rmessage/subscriber.rb', line 18 def setup_subscription(channel: @channel, auto_parse: false, logger: nil, connection: nil, connection_index: 0, &_) redis_connection = connection || RMessage::CONNECTION_POOL[connection_index] redis_connection.subscribe(channel) do |event| event.subscribe do logger&.info("Subscribed to channel [channel: #{channel}]") end event. do |_, | auto_parse ? yield(()) : yield() logger&.info("Received Message: #{}") end end end |