Ømq & Services @ Chartboost
-
Upload
kenneth-ballenegger -
Category
Technology
-
view
1.101 -
download
0
description
Transcript of Ømq & Services @ Chartboost
![Page 1: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/1.jpg)
ØMQ &SERVICES
![Page 2: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/2.jpg)
ØMQ &SERVICES
part i: zeromq
![Page 3: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/3.jpg)
wtf is zmq?
![Page 4: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/4.jpg)
Zeromq is what bsd sockets may have looked like, if they were designed today.”
“
![Page 5: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/5.jpg)
Zeromq is a communication library.
![Page 6: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/6.jpg)
# C & C++void *context = zmq_init(1);
# rubycontext = ZMQ::Context.new(1)
# php$context = new ZMQContext(1);
# etc.
polyglot
![Page 7: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/7.jpg)
atomic
finite&
![Page 8: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/8.jpg)
messaging patterns
![Page 9: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/9.jpg)
request/reply
client server
blah?
blah!
![Page 10: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/10.jpg)
request/reply
server
clientserver
client
client
client
![Page 11: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/11.jpg)
request/reply
server
clientserver
client
client
client
![Page 12: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/12.jpg)
request/reply
server
clientserver
client
client
client
![Page 13: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/13.jpg)
push/pull
pusher pullerblah!
![Page 14: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/14.jpg)
push/pull
STEP 2
node
node
node
node
STEP 1 STEP 3
node
node
node
![Page 15: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/15.jpg)
node
push/pull
STEP 2
node
node
node
node
STEP 1 STEP 3
node
node
![Page 16: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/16.jpg)
node
push/pull
STEP 2
node
node
node
node
STEP 1 STEP 3
node
node
![Page 17: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/17.jpg)
pub/sub
subscriber
subscriber
subscriber
subscriber
publisher
![Page 18: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/18.jpg)
pub/sub
subscriber
subscriber
subscriber
subscriber
publisher
![Page 19: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/19.jpg)
pub/sub
subscriber
subscriber
subscriber
subscriber
publisher
![Page 20: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/20.jpg)
irl
client server
subscriber
worker worker subscriber
REQ
PUSHPUSH
PUSH PUB
PUB
node
node
node
node node
![Page 21: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/21.jpg)
examples
![Page 22: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/22.jpg)
a chat service
chat server
seankenneth mark
![Page 23: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/23.jpg)
a chat service
chat server
seankenneth mark
pub pub pub
push
![Page 24: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/24.jpg)
a chat service
chat server
seankenneth markhi!hi!hi!
![Page 25: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/25.jpg)
a chat service
chat server
seankenneth markhi!hi!hi!
![Page 26: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/26.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needpub = context.socket(ZMQ::PUB)pull = context.socket(ZMQ::PULL)
# bind the socketspub.bind('tcp://*:1338')pull.bind('tcp://*:1337')
# wait for input, and forward to all subscriberswhile body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}"end
server.rb
![Page 27: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/27.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needpub = context.socket(ZMQ::PUB)pull = context.socket(ZMQ::PULL)
# bind the socketspub.bind('tcp://*:1338')pull.bind('tcp://*:1337')
# wait for input, and forward to all subscriberswhile body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}"end
server.rb
![Page 28: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/28.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needpub = context.socket(ZMQ::PUB)pull = context.socket(ZMQ::PULL)
# bind the socketspub.bind('tcp://*:1338')pull.bind('tcp://*:1337')
# wait for input, and forward to all subscriberswhile body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}"end
server.rb
![Page 29: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/29.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needpub = context.socket(ZMQ::PUB)pull = context.socket(ZMQ::PULL)
# bind the socketspub.bind('tcp://*:1338')pull.bind('tcp://*:1337')
# wait for input, and forward to all subscriberswhile body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}"end
server.rb
![Page 30: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/30.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needpub = context.socket(ZMQ::PUB)pull = context.socket(ZMQ::PULL)
# bind the socketspub.bind('tcp://*:1338')pull.bind('tcp://*:1337')
# wait for input, and forward to all subscriberswhile body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}"end
server.rb
![Page 31: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/31.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 32: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/32.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 33: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/33.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 34: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/34.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 35: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/35.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 36: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/36.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 37: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/37.jpg)
a chat service# create the contextcontext = ZMQ::Context.new(1)
# create the two sockets we needsub = context.socket(ZMQ::SUB)sub.setsockopt(ZMQ::SUBSCRIBE, '')push = context.socket(ZMQ::PUSH)
# bind the socketssub.connect("tcp://#{server}:1338")push.connect("tcp://#{server}:1337")
# wait for some inputwhile line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK))end
client.rb
![Page 38: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/38.jpg)
demo$ git clone https://github.com/ \ ChartBoost/zmq-examples.git
$ bundle install
$ ruby chat/client.rb
![Page 39: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/39.jpg)
demo$ git clone https://github.com/ \ ChartBoost/zmq-examples.git
$ bundle install
$ ruby chat/client.rb
![Page 40: Ømq & Services @ Chartboost](https://reader034.fdocuments.us/reader034/viewer/2022051608/5404ed668d7f729e768b4997/html5/thumbnails/40.jpg)
thanks@KOB — [email protected]