Created
April 9, 2013 11:35
-
-
Save realmyst/5345008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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