class Vines::Cluster::Publisher
Broadcast messages to other cluster nodes via redis pubsub channels. All members subscribe to a channel for heartbeats, online, and offline messages from other nodes. This allows new nodes to be added to the cluster dynamically, without configuring all other nodes.
Constants
- USER
Public Class Methods
new(cluster)
click to toggle source
# File lib/vines/cluster/publisher.rb, line 14 def initialize(cluster) @cluster = cluster end
Public Instance Methods
broadcast(type)
click to toggle source
Publish a :heartbeat, :online, or :offline message to the nodes:all broadcast channel.
# File lib/vines/cluster/publisher.rb, line 20 def broadcast(type) redis.publish(ALL, { from: @cluster.id, type: type, time: Time.now.to_i }.to_json) end
redis()
click to toggle source
# File lib/vines/cluster/publisher.rb, line 50 def redis @cluster.connection end
route(stanza, node)
click to toggle source
Send the stanza to the node hosting the user's session. The stanza is published to the channel to which the remote node is listening for messages.
# File lib/vines/cluster/publisher.rb, line 31 def route(stanza, node) log.debug { "Sent cluster stanza: %s -> %s\n%s\n" % [@cluster.id, node, stanza] } redis.publish("cluster:nodes:#{node}", { from: @cluster.id, type: STANZA, stanza: stanza.to_s }.to_json) end
update_user(jid, node)
click to toggle source
Notify the remote node that the user's roster has changed and it should reload the user from storage.
# File lib/vines/cluster/publisher.rb, line 42 def update_user(jid, node) redis.publish("cluster:nodes:#{node}", { from: @cluster.id, type: USER, jid: jid.to_s }.to_json) end