Class: SimplePubSub::Client::PubSub

Inherits:
Object
  • Object
show all
Defined in:
lib/simplepubsub.rb

Defined Under Namespace

Classes: Echo

Instance Method Summary collapse

Constructor Details

#initialize(hostname) ⇒ PubSub

Returns a new instance of PubSub.



29
30
31
# File 'lib/simplepubsub.rb', line 29

def initialize(hostname)
  @hostname = hostname
end

Instance Method Details

#get(topic, &get_proc) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/simplepubsub.rb', line 33

def get(topic, &get_proc)

  DRb.start_service nil, Echo.new(&get_proc)
   
  obj = DRbObject.new nil, "druby://#{@hostname}:59000"
  obj.subscribe(topic, DRb.uri)
  DRb.thread.join        

end

#publish(topic, message) ⇒ Object



43
44
45
46
47
48
# File 'lib/simplepubsub.rb', line 43

def publish(topic, message)

  DRb.start_service
  obj = DRbObject.new nil, "druby://#{@hostname}:59000"
  obj.deliver topic, message
end