Celluloid Presence

Start an instance of ZooKeeper on your dev machine then run:


require 'rubygems'
require 'celluloid-presence'

Celluloid::Presence::ZkService.init :server => 'localhost'
Celluloid::Presence::ZkPresence.supervise_as :presence, :service_name => :presence

class Messaging
  include Celluloid
  include Celluloid::Notifications
  
  def self.finalizer
    :finalize
  end
  
  def initialize(service_name)
    @service_name = service_name
    subscribe("#{@service_name}_nodes", :node_update)
  end
  
  def node_update(event, nodes)
    p "\nNode list updated!"
    nodes.each do |node|
      p " -> #{Actor[@service_name].get(node)}"
    end
  end
  
  
  private
  
  
  def finalize
    Actor[@service_name].terminate
  end
end

Messaging.run(:presence)

Start using it now

  1. Read the Documentation
  2. Then gem install celluloid-presence