Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ømq & Services @ Chartboost

Ømq & Services @ Chartboost

This is an internal talk I gave at Chartboost on ZeroMq and how it can power distributed systems.

Kenneth Ballenegger

November 07, 2012
Tweet

More Decks by Kenneth Ballenegger

Other Decks in Programming

Transcript

  1. Zeromq is what bsd sockets may have looked like, if

    they were designed today.” “
  2. # C & C++ void *context = zmq_init(1); # ruby

    context = ZMQ::Context.new(1) # php $context = new ZMQContext(1); # etc. polyglot
  3. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need pub = context.socket(ZMQ::PUB) pull = context.socket(ZMQ::PULL) # bind the sockets pub.bind('tcp://*:1338') pull.bind('tcp://*:1337') # wait for input, and forward to all subscribers while body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}" end server.rb
  4. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need pub = context.socket(ZMQ::PUB) pull = context.socket(ZMQ::PULL) # bind the sockets pub.bind('tcp://*:1338') pull.bind('tcp://*:1337') # wait for input, and forward to all subscribers while body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}" end server.rb
  5. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need pub = context.socket(ZMQ::PUB) pull = context.socket(ZMQ::PULL) # bind the sockets pub.bind('tcp://*:1338') pull.bind('tcp://*:1337') # wait for input, and forward to all subscribers while body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}" end server.rb
  6. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need pub = context.socket(ZMQ::PUB) pull = context.socket(ZMQ::PULL) # bind the sockets pub.bind('tcp://*:1338') pull.bind('tcp://*:1337') # wait for input, and forward to all subscribers while body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}" end server.rb
  7. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need pub = context.socket(ZMQ::PUB) pull = context.socket(ZMQ::PULL) # bind the sockets pub.bind('tcp://*:1338') pull.bind('tcp://*:1337') # wait for input, and forward to all subscribers while body = pull.recv payload = JSON.parse(body) pub.send "#{payload['user']}> #{payload['message'].cyan}" end server.rb
  8. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  9. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  10. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  11. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  12. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  13. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb
  14. a chat service # create the context context = ZMQ::Context.new(1)

    # create the two sockets we need sub = context.socket(ZMQ::SUB) sub.setsockopt(ZMQ::SUBSCRIBE, '') push = context.socket(ZMQ::PUSH) # bind the sockets sub.connect("tcp://#{server}:1338") push.connect("tcp://#{server}:1337") # wait for some input while line = gets.chomp push.send(line) unless line == '' # dump buffered messages puts buffered_msg while (buffered_msg = sub.recv(ZMQ::NOBLOCK)) end client.rb