SlideShare a Scribd company logo
1 of 40
Download to read offline
Ø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

What's hot (11)

Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
 
692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w
 
Docker networking
Docker networkingDocker networking
Docker networking
 
Curl
CurlCurl
Curl
 
How to run multiple instances of transmission daemon in linux debian or ubuntu
How to run multiple instances of transmission daemon in linux debian or ubuntuHow to run multiple instances of transmission daemon in linux debian or ubuntu
How to run multiple instances of transmission daemon in linux debian or ubuntu
 
Java sockets
Java socketsJava sockets
Java sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
debugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitchdebugging openstack neutron /w openvswitch
debugging openstack neutron /w openvswitch
 
解读server.xml文件
解读server.xml文件解读server.xml文件
解读server.xml文件
 
Single Host Docker Networking
Single Host Docker NetworkingSingle Host Docker Networking
Single Host Docker Networking
 

Viewers also liked

Stages of problem solving presentation
Stages of problem solving presentationStages of problem solving presentation
Stages of problem solving presentation
bbaugh
 
Tweet Tweet Tweet Twitter
Tweet Tweet Tweet TwitterTweet Tweet Tweet Twitter
Tweet Tweet Tweet Twitter
Jimmy Jay
 
Cubicle Ninjas' Code of Honor
Cubicle Ninjas' Code of HonorCubicle Ninjas' Code of Honor
Cubicle Ninjas' Code of Honor
Cubicle Ninjas
 
The Do's and Don'ts of Presentations
The Do's and Don'ts of Presentations The Do's and Don'ts of Presentations
The Do's and Don'ts of Presentations
Cubicle Ninjas
 
FontShop - Typography
FontShop - TypographyFontShop - Typography
FontShop - Typography
Poppy Young
 

Viewers also liked (20)

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

Similar to Ømq & Services @ Chartboost

ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
James Dennis
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
Robin Xiao
 
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docxRunning Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
cowinhelen
 
In depth understanding network security
In depth understanding network securityIn depth understanding network security
In depth understanding network security
Thanawan Tuamyim
 
Netcat 101 by-mahesh-beema
Netcat 101 by-mahesh-beemaNetcat 101 by-mahesh-beema
Netcat 101 by-mahesh-beema
Raghunath G
 

Similar to Ømq & Services @ Chartboost (20)

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

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Ø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

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n