Ømq & services @ chartboost

40
ØMQ & SERVICES

Upload: kenneth-ballenegger

Post on 01-Sep-2014

1.101 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Ømq & Services @ Chartboost

ØMQ &SERVICES

Page 2: Ømq & Services @ Chartboost

ØMQ &SERVICES

part i: zeromq

Page 3: Ømq & Services @ Chartboost

wtf is zmq?

Page 4: Ømq & Services @ Chartboost

Zeromq is what bsd sockets may have looked like, if they were designed today.”

Page 5: Ømq & Services @ Chartboost

Zeromq is a communication library.

Page 6: Ømq & Services @ Chartboost

# C & C++void *context = zmq_init(1);

# rubycontext = ZMQ::Context.new(1)

# php$context = new ZMQContext(1);

# etc.

polyglot

Page 7: Ømq & Services @ Chartboost

atomic

finite&

Page 8: Ømq & Services @ Chartboost

messaging patterns

Page 9: Ømq & Services @ Chartboost

request/reply

client server

blah?

blah!

Page 10: Ømq & Services @ Chartboost

request/reply

server

clientserver

client

client

client

Page 11: Ømq & Services @ Chartboost

request/reply

server

clientserver

client

client

client

Page 12: Ømq & Services @ Chartboost

request/reply

server

clientserver

client

client

client

Page 13: Ømq & Services @ Chartboost

push/pull

pusher pullerblah!

Page 14: Ømq & Services @ Chartboost

push/pull

STEP 2

node

node

node

node

STEP 1 STEP 3

node

node

node

Page 15: Ømq & Services @ Chartboost

node

push/pull

STEP 2

node

node

node

node

STEP 1 STEP 3

node

node

Page 16: Ømq & Services @ Chartboost

node

push/pull

STEP 2

node

node

node

node

STEP 1 STEP 3

node

node

Page 17: Ømq & Services @ Chartboost

pub/sub

subscriber

subscriber

subscriber

subscriber

publisher

Page 18: Ømq & Services @ Chartboost

pub/sub

subscriber

subscriber

subscriber

subscriber

publisher

Page 19: Ømq & Services @ Chartboost

pub/sub

subscriber

subscriber

subscriber

subscriber

publisher

Page 20: Ømq & Services @ Chartboost

irl

client server

subscriber

worker worker subscriber

REQ

PUSHPUSH

PUSH PUB

PUB

node

node

node

node node

Page 21: Ømq & Services @ Chartboost

examples

Page 22: Ømq & Services @ Chartboost

a chat service

chat server

seankenneth mark

Page 23: Ømq & Services @ Chartboost

a chat service

chat server

seankenneth mark

pub pub pub

push

Page 24: Ømq & Services @ Chartboost

a chat service

chat server

seankenneth markhi!hi!hi!

Page 25: Ømq & Services @ Chartboost

a chat service

chat server

seankenneth markhi!hi!hi!

Page 26: Ømq & Services @ Chartboost

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

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

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

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

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

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

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

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

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

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

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

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

demo$ git clone https://github.com/ \ ChartBoost/zmq-examples.git

$ bundle install

$ ruby chat/client.rb

Page 39: Ømq & Services @ Chartboost

demo$ git clone https://github.com/ \ ChartBoost/zmq-examples.git

$ bundle install

$ ruby chat/client.rb

Page 40: Ømq & Services @ Chartboost

thanks@KOB — [email protected]