Created
March 14, 2015 23:58
-
-
Save niamster/5c5ce7a1fa1587f9b3eb to your computer and use it in GitHub Desktop.
Celluloid 0MQ router
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 'celluloid/zmq' | |
Celluloid::ZMQ.init | |
class Server | |
include Celluloid::ZMQ | |
def initialize(address) | |
@socket = RouterSocket.new | |
@socket.set ::ZMQ::SNDHWM, 0 | |
@socket.set ::ZMQ::RCVHWM, 0 | |
begin | |
@socket.bind(address) | |
rescue IOError | |
@socket.close | |
raise | |
end | |
end | |
def run | |
loop do | |
async.handle_message @socket.read_multipart | |
end | |
end | |
def handle_message(parts) | |
puts "PARTS: #{parts.inspect}" | |
@socket.send(parts[0], parts[1], "Received #{parts[2]}") | |
end | |
end | |
addr = 'tcp://127.0.0.1:3435' | |
server = Server.new(addr) | |
server.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment