Ømq & Services @ Chartboost
Upcoming SlideShare
Loading in...5
×
 

Ømq & Services @ Chartboost

on

  • 1,103 views

 

Statistics

Views

Total Views
1,103
Views on SlideShare
1,103
Embed Views
0

Actions

Likes
2
Downloads
42
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Ømq & Services @ Chartboost Ømq & Services @ Chartboost Presentation Transcript

  • ØM Q &SERVIC ES
  • ØM Q &SERVIC ES part i: zeromq
  • wtf is zmq?
  • “ Zeromq is what bsd sockets may have looked like, if they were designed today.”
  • Zeromq is acommunicationlibrary.
  • polyglot# C & C++void *context = zmq_init(1);# rubycontext = ZMQ::Context.new(1)# php$context = new ZMQContext(1);# etc.
  • atomic & finite
  • aging patte rnsm ess
  • request/reply blah? client server blah!
  • request/reply client server client client server client
  • request/reply client server client client server client
  • request/reply client server client client server client
  • push/pull blah! pusher puller
  • push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  • push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  • push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  • pub/sub subscriber subscriber publisher subscriber subscriber
  • pub/sub subscriber subscriber publisher subscriber subscriber
  • pub/sub subscriber subscriber publisher subscriber subscriber
  • nodeirl nodeclient REQ server node PUS USH H Pworker PUSH worker PUB subscriber PUB node node subscriber
  • examples
  • a chat service chat server kenneth sean mark
  • a chat service chat server pub pub pub push kenneth sean mark
  • a chat service chat server hi! kenneth sean mark
  • a chat service chat server hi! kenneth hi! sean hi! mark
  • a chat service# create the context server.rbcontext = 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
  • a chat service# create the context server.rbcontext = 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
  • a chat service# create the context server.rbcontext = 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
  • a chat service# create the context server.rbcontext = 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
  • a chat service# create the context server.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • a chat service# create the context client.rbcontext = 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
  • demo$ git clone https://github.com/ ChartBoost/zmq-examples.git$ bundle install$ ruby chat/client.rb
  • demo$ git clone https://github.com/ ChartBoost/zmq-examples.git$ bundle install$ ruby chat/client.rb
  • thanks@KOB — KENNETH@CHARTBOOST.COM