SlideShare a Scribd company logo
Ø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 a
communication
library.
polyglot
# C & C++
void *context = zmq_init(1);
# ruby
context = ZMQ::Context.new(1)
# php
$context = new ZMQContext(1);
# etc.
atomic
         & finite
aging patte rns
m 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
node
irl                                       node


client         REQ
                     server               node
                                PUS
             USH                    H
         P



worker        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.rb
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
a chat service
# create the context                                      server.rb
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
a chat service
# create the context                                      server.rb
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
a chat service
# create the context                                      server.rb
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
a chat service
# create the context                                      server.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
a chat service
# create the context                                      client.rb
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
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

More Related Content

KEY
Ruby Concurrency and EventMachine
PDF
Redis cluster
PPTX
zeromq
PDF
DASP Top10 for OWASP Thailand Chapter by s111s
ODP
Pfm technical-inside
PPT
PPT
03 sockets
Ruby Concurrency and EventMachine
Redis cluster
zeromq
DASP Top10 for OWASP Thailand Chapter by s111s
Pfm technical-inside
03 sockets

What's hot (11)

PPTX
Ruby C10K: High Performance Networking - RubyKaigi '09
DOCX
Udp socket programming(Florian)
DOCX
692015 programming assignment 1 building a multi­threaded w
PPTX
Docker networking
PDF
PDF
How to run multiple instances of transmission daemon in linux debian or ubuntu
PDF
Java sockets
PPT
Socket programming
PDF
debugging openstack neutron /w openvswitch
DOC
解读server.xml文件
PPTX
Single Host Docker Networking
Ruby C10K: High Performance Networking - RubyKaigi '09
Udp socket programming(Florian)
692015 programming assignment 1 building a multi­threaded w
Docker networking
How to run multiple instances of transmission daemon in linux debian or ubuntu
Java sockets
Socket programming
debugging openstack neutron /w openvswitch
解读server.xml文件
Single Host Docker Networking
Ad

Viewers also liked (20)

PDF
Design Patterns : Solution to Software Design Problems
PPTX
Build reliable, traceable, distributed systems with ZeroMQ
PPTX
The Important Book by Mrs. Henson's Class
PPTX
Basic tutorial how to use slideshare
PPT
Stages of problem solving presentation
PDF
How to Teach Yourself to Code
PDF
Introduction to Slide Design: 7 Rules for Creating Effective Slides
PDF
Tweet Tweet Tweet Twitter
PDF
16 things that Panhandlers can teach us about Content Marketing
PPTX
Cubicle Ninjas' Code of Honor
PPT
Email and tomorrow
PDF
Hashtag 101 - All You Need to Know About Hashtags
PPTX
The Do's and Don'ts of Presentations
PPTX
Using Color to Convey Data in Charts
PPTX
The no bullet bullet slide
PDF
Amazing First Slide Picture Templates
PDF
Weekly Inspirational Quotes by Fun Team Building
PDF
Preparing to fail
PPT
Effective Use of Icons & Images
PDF
FontShop - Typography
Design Patterns : Solution to Software Design Problems
Build reliable, traceable, distributed systems with ZeroMQ
The Important Book by Mrs. Henson's Class
Basic tutorial how to use slideshare
Stages of problem solving presentation
How to Teach Yourself to Code
Introduction to Slide Design: 7 Rules for Creating Effective Slides
Tweet Tweet Tweet Twitter
16 things that Panhandlers can teach us about Content Marketing
Cubicle Ninjas' Code of Honor
Email and tomorrow
Hashtag 101 - All You Need to Know About Hashtags
The Do's and Don'ts of Presentations
Using Color to Convey Data in Charts
The no bullet bullet slide
Amazing First Slide Picture Templates
Weekly Inspirational Quotes by Fun Team Building
Preparing to fail
Effective Use of Icons & Images
FontShop - Typography
Ad

Similar to Ømq & Services @ Chartboost (20)

PPTX
ZeroMQ: Super Sockets - by J2 Labs
PDF
Zmq in context of openstack
KEY
Message queueing
DOCX
NS2 (1).docx
PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
PDF
Deep dive in container service discovery
KEY
Message Queueing - by an MQ noob
PDF
Lindsay distributed geventzmq
PDF
FreeBSD, ipfw and OpenVPN 2.1 server
PPTX
DMVPN configuration - Configuring Cisco dynamic Multipoint VPN - HUB, SPOKES,...
DOCX
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
PPTX
201904 websocket
PPT
Client server
KEY
Servers with Event Machine - David Troy - RailsConf 2011
PPT
In depth understanding network security
PDF
ZeroMQ - Sockets on steroids!
DOC
Router commands
PDF
Netcat 101 by-mahesh-beema
PDF
Netcat - 101 Swiss Army Knife
PPTX
[오픈소스컨설팅] Linux Network Troubleshooting
ZeroMQ: Super Sockets - by J2 Labs
Zmq in context of openstack
Message queueing
NS2 (1).docx
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Deep dive in container service discovery
Message Queueing - by an MQ noob
Lindsay distributed geventzmq
FreeBSD, ipfw and OpenVPN 2.1 server
DMVPN configuration - Configuring Cisco dynamic Multipoint VPN - HUB, SPOKES,...
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
201904 websocket
Client server
Servers with Event Machine - David Troy - RailsConf 2011
In depth understanding network security
ZeroMQ - Sockets on steroids!
Router commands
Netcat 101 by-mahesh-beema
Netcat - 101 Swiss Army Knife
[오픈소스컨설팅] Linux Network Troubleshooting

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
KodekX | Application Modernization Development
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Big Data Technologies - Introduction.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Programs and apps: productivity, graphics, security and other tools
MIND Revenue Release Quarter 2 2025 Press Release
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Teaching material agriculture food technology

Ømq & Services @ Chartboost

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

Editor's Notes