Skip to content

Instantly share code, notes, and snippets.

@realmyst
Created April 9, 2013 11:35
Show Gist options
  • Save realmyst/5345008 to your computer and use it in GitHub Desktop.
Save realmyst/5345008 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'zmq'
require 'json'
context = ::ZMQ::Context.new
listen_socket = context.socket(::ZMQ::SUB)
listen_socket = listen_socket.setsockopt(::ZMQ::SUBSCRIBE, "")
listen_socket.bind("tcp://0.0.0.0:5555")
broadcast_socket = context.socket(::ZMQ::PUB)
broadcast_socket.bind("tcp://0.0.0.0:5557")
loop do
original_msg = listen_socket.recv
hash_msg = JSON.parse(original_msg)
puts "broadcast send channel: #{hash_msg['_channel']}"
broadcast_socket.send(hash_msg["_channel"], ::ZMQ::SNDMORE)
puts "broadcast send original_msg: #{original_msg}"
broadcast_socket.send(original_msg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment