Class: Vines::Cluster::Subscriber

Inherits:
Object
  • Object
show all
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

Methods included from Log

#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
  process_messages
end

Instance Method Details

#subscribeObject

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, message|
    @messages.push([channel, message])
  end
end