-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrrbroker.rb
38 lines (33 loc) · 816 Bytes
/
rrbroker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
require 'rbczmq'
context = ZMQ::Context.new
frontend = context.socket ZMQ::ROUTER
backend = context.socket ZMQ::DEALER
frontend.bind 'tcp://*:5559'
backend.bind 'tcp://*:5560'
class FrontEnd < ZMQ::Handler
def initialize(pollitem, frontend, backend)
super
@frontend = frontend
@backend = backend
end
def on_readable
message = @frontend.recv_message
@backend.send_message(message)
end
end
class BackEnd < ZMQ::Handler
def initialize(pollitem, backend, frontend)
super
@backend = backend
@frontend = frontend
end
def on_readable
message = @backend.recv_message
@frontend.send_message(message)
end
end
ZL.run do
ZL.register_readable(frontend, FrontEnd, frontend, backend)
ZL.register_readable(backend, BackEnd, backend, frontend)
end