Sha256: bfb41137227269a03ef34343e7af55a460b5eb79d025703d20409a27763da680

Contents?: true

Size: 887 Bytes

Versions: 3

Compression:

Stored size: 887 Bytes

Contents

require 'dripdrop/node'
Thread.abort_on_exception = true

#Define our handlers
DripDrop::Node.new do
  z_addr = 'tcp://127.0.0.1:2200'
    
  #Create a publisher
  pub = zmq_publish(z_addr,:bind)

  #Create three subscribers
  sub1 = zmq_subscribe(z_addr,:connect)

  sub1.on_recv do |message|
    puts "Receiver 1 #{message.inspect}"
  end

  sub1.topic_filter = /[13579]$/

  sub2 = zmq_subscribe(z_addr,:connect)

  sub2.on_recv do |message|
    puts "Receiver 2 #{message.inspect}"
  end

  sub2.topic_filter = /[02468]$/

  zmq_subscribe(z_addr, :connect).on_recv do |message|
    puts "Receiver 3 #{message.inspect}"
  end
  
  zm_reactor.periodical_timer(5) do
    #Sending a hash as a message implicitly transforms it into a DripDrop::Message
    pub.send_message(:name => Time.now.to_i.to_s, :body => 'Test Payload')
  end
end.start! #Start the reactor and block until complete

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dripdrop-0.3.1 example/pubsub.rb
dripdrop-0.3.0 example/pubsub.rb
dripdrop-0.2.0 example/pubsub.rb