Class: Vines::Cluster::Subscriber
- Inherits:
-
Object
- Object
- Vines::Cluster::Subscriber
- Includes:
- Log
- Defined in:
- lib/vines/cluster/subscriber.rb
Overview
Subscribes to the redis nodes:all broadcast channel to listen for heartbeats from other cluster members. Also subscribes to a channel exclusively for this particular node, listening for stanzas routed to us from other nodes.
Instance Method Summary collapse
-
#initialize(cluster) ⇒ Subscriber
constructor
A new instance of Subscriber.
-
#subscribe ⇒ Object
Create a new redis connection and subscribe to the nodes:all broadcast channel as well as the channel for this cluster node.
Methods included from Log
Constructor Details
#initialize(cluster) ⇒ Subscriber
Returns a new instance of Subscriber.
15 16 17 18 19 20 |
# File 'lib/vines/cluster/subscriber.rb', line 15 def initialize(cluster) @cluster = cluster @channel = "cluster:nodes:#{@cluster.id}" @messages = EM::Queue.new end |
Instance Method Details
#subscribe ⇒ Object
Create a new redis connection and subscribe to the nodes:all broadcast channel as well as the channel for this cluster node. Redis connections in subscribe mode cannot be used for other key/value operations.
25 26 27 28 29 30 31 32 |
# File 'lib/vines/cluster/subscriber.rb', line 25 def subscribe conn = @cluster.connect conn.subscribe(ALL) conn.subscribe(@channel) conn.on(:message) do |channel, | @messages.push([channel, ]) end end |