Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ømq & Services @ Chartboost

1,486 views

Published on

Published in: Technology, Education
  • Be the first to comment

Ømq & Services @ Chartboost

  1. 1. ØM Q &SERVIC ES
  2. 2. ØM Q &SERVIC ES part i: zeromq
  3. 3. wtf is zmq?
  4. 4. “ Zeromq is what bsd sockets may have looked like, if they were designed today.”
  5. 5. Zeromq is acommunicationlibrary.
  6. 6. polyglot# C & C++void *context = zmq_init(1);# rubycontext = ZMQ::Context.new(1)# php$context = new ZMQContext(1);# etc.
  7. 7. atomic & finite
  8. 8. aging patte rnsm ess
  9. 9. request/reply blah? client server blah!
  10. 10. request/reply client server client client server client
  11. 11. request/reply client server client client server client
  12. 12. request/reply client server client client server client
  13. 13. push/pull blah! pusher puller
  14. 14. push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  15. 15. push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  16. 16. push/pull STEP 1 STEP 2 STEP 3 node node node node node node node
  17. 17. pub/sub subscriber subscriber publisher subscriber subscriber
  18. 18. pub/sub subscriber subscriber publisher subscriber subscriber
  19. 19. pub/sub subscriber subscriber publisher subscriber subscriber
  20. 20. nodeirl nodeclient REQ server node PUS USH H Pworker PUSH worker PUB subscriber PUB node node subscriber
  21. 21. examples
  22. 22. a chat service chat server kenneth sean mark
  23. 23. a chat service chat server pub pub pub push kenneth sean mark
  24. 24. a chat service chat server hi! kenneth sean mark
  25. 25. a chat service chat server hi! kenneth hi! sean hi! mark
  26. 26. 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
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. 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
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. 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
  36. 36. 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
  37. 37. 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
  38. 38. demo$ git clone https://github.com/ ChartBoost/zmq-examples.git$ bundle install$ ruby chat/client.rb
  39. 39. demo$ git clone https://github.com/ ChartBoost/zmq-examples.git$ bundle install$ ruby chat/client.rb
  40. 40. thanks@KOB — KENNETH@CHARTBOOST.COM

×