SlideShare a Scribd company logo
1 of 27
ZeroMQ: Super Sockets By James Dennis (@j2labs) http://j2labs.net
What is ZeroMQ? Message Passing You still design the payload Fault tolerant A message IS your payload even when broken into multiple packets Many messaging “patterns” offered
What is ZeroMQ? Super Sockets Multiple networking protocols(tcp, ipc, whatevz!) Language agnostic (bindings for: ruby, python, java, c, lua, lisp, scheme and more…) Feels like a scripting language for sockets Socket behaviors Round-robin routing Publishing to subscribers Sending job requests
What ZeroMQ is not… Persistent reasonably easy to add A message queue there are literally zero mq’s here An out-of-the-box solution instead, it’s easy to build any solution remember, they’re like scripting sockets
Socket Types (transports) tcp :: regular TCP sockets socket.connect(“tcp://…”) ipc :: interprocess communication (unix sockets) socket.connect(“ipc://…”) in-proc :: in process communication socket.connect(“in-proc://…”) pgm – pragmatic multicast (or epgmvia udp) socket.connect(“pgm://…”)
Socket Behaviors Actually called patterns They exist to make typical cases easy Request-Reply Publish-Subscribe Pipeline Exclusive pair you probably don’t want this
Patterns: PUSH/PULL Sends messages to multiple connected hosts Passes messages ROUND ROBIN to connections Blocks PUSH socket if no connections are present N hosts PULL messages from pusher Connect/Remove new hosts as necessary
Patterns: PUSH/PULL Server: Sends a message import zmq ctx = zmq.Context() s = ctx.socket(zmq.PUSH) s.bind("ipc://*:5678") while True: s.send(”blablabla") # blocks if no receivers     print “Sent one”
Patterns: PUSH/PULL Client: Prints messages from server socket import zmq ctx = zmq.Context() s = ctx.socket(zmq.PULL) s.connect("ipc://*:5678") while True: msg = s.recv()     print 'Got msg:', msg
Patterns: PUSH/PULL A typical worker pipeline  looks a bit like this. What’s that PUB/SUB stuff?
Patterns: PUB/SUB PUB socket sends topical payloads Can start streaming messages right away ZMQ discards messages if no subscribers exist SUB socket subscribes to “topic” receives all messages reads topic and discards accordingly happens under the hood.
Patterns: PUB/ SUB Server: sends messages to `whatevz` s = ctx.socket(zmq.PUB) s.bind("tcp://127.0.0.1:5566") topic = ’whatevz’ message = json.dumps({'msg': 'what up dude?'}) while True: s.send(topic, message) # send to topic     print ‘Sent one’
Patterns: PUB/SUB Client: demonstrates subscribing to `whatevz` s = ctx.socket(zmq.SUB) s.connect("tcp://127.0.0.1:5566") topic = "whatevz" s.setsockopt(zmq.SUBSCRIBE, topic) # set socket option while True: msg = s.recv()     print 'Got msg:’, json.loads(msg)
Patterns: REQ/REP One to one messaging Each REQ message must have a REP response Synchronous communication Will error if two REQ’s are sent before one REP
Patterns REQ/REP Client context.socket(zmq.REQ) # btw… REQ sockets are blocking! Worker(could say “server”) context.socket(zmq.REP) Multiple Connections One-to-one messaging is useful for workers getting work Basically, pull work request & reply when done Client may need to multiple workers Can’t just open more sockets… we need a new pattern…
Patterns: REQ/REP CLIENTsends a “Hello” SERVERsends a “world” back The REQ socket can send a message, but must not send anything else until it gets a response or ZMQ will error. Likewise, a REP socket cannot send a message unless it first received one.
Synchronized PUB/SUB Handling “no broker” (aka building one) More than one socket used Like having OneMQ now Hypothetical Communication Order: Subscriber sends sub REQ for topic Publisher REP - “listen <tcp://here>” Subscriber listens to PUB socket
Patterns: XREQ/XREP XREQ is a historical name for DEALER A DEALER asynchronously sends to *REP sockets It can send to XREP (aka: ROUTER) sockets too XREP is a historical name for ROUTER A ROUTER asynchronously handles *REQ sockets It can handle DEALER (aka: XREQ) sockets too.
Patterns: DEALER/ROUTER ,[object Object]
ROUTER processes message and sends to some worker via the DEALER
DEALERsends message to worker and waits for one response
WORKER processes message, sends response back
DEALER get message from WORKER, sends along to ROUTER
ROUTERgets message and sends back to CLIENT
CLIENTdoes something with it!,[object Object]
Broker Model: aka “The Titanic”
Broker Model with ZMQ Every connection is a REQ socket ROUTER socket to all connections LRU Queue (your broker code!) Up to the LRU Queue handle socket identities properly REQ/REP gets that for free.

More Related Content

What's hot

Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Giacomo Vacca
 
Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromqDongmin Yu
 
제3회난공불락 오픈소스 인프라세미나 - Pacemaker
제3회난공불락 오픈소스 인프라세미나 - Pacemaker제3회난공불락 오픈소스 인프라세미나 - Pacemaker
제3회난공불락 오픈소스 인프라세미나 - PacemakerTommy Lee
 
Software architecture for high traffic website
Software architecture for high traffic websiteSoftware architecture for high traffic website
Software architecture for high traffic websiteTung Nguyen Thanh
 
FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sChien Cheng Wu
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzerDmitry Vyukov
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecturehugo lu
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기NeoClova
 
Getting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopGetting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopstefansayer
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDKKernel TLV
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestratorYoungHeon (Roy) Kim
 
MiVoice Business software versions through time
MiVoice Business software versions through timeMiVoice Business software versions through time
MiVoice Business software versions through timedenwacomms
 
libuv, NodeJS and everything in between
libuv, NodeJS and everything in betweenlibuv, NodeJS and everything in between
libuv, NodeJS and everything in betweenSaúl Ibarra Corretgé
 
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentThree Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentFred Posner
 
Troubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesTroubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesMichael Klishin
 
So You Want to Write a Connector?
So You Want to Write a Connector? So You Want to Write a Connector?
So You Want to Write a Connector? confluent
 

What's hot (20)

Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017
 
Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromq
 
Kamailio - Secure Communication
Kamailio - Secure CommunicationKamailio - Secure Communication
Kamailio - Secure Communication
 
제3회난공불락 오픈소스 인프라세미나 - Pacemaker
제3회난공불락 오픈소스 인프라세미나 - Pacemaker제3회난공불락 오픈소스 인프라세미나 - Pacemaker
제3회난공불락 오픈소스 인프라세미나 - Pacemaker
 
Mule caching strategy with redis cache
Mule caching strategy with redis cacheMule caching strategy with redis cache
Mule caching strategy with redis cache
 
Software architecture for high traffic website
Software architecture for high traffic websiteSoftware architecture for high traffic website
Software architecture for high traffic website
 
FreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8sFreeSWITCH Cluster by K8s
FreeSWITCH Cluster by K8s
 
syzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzersyzkaller: the next gen kernel fuzzer
syzkaller: the next gen kernel fuzzer
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
Kamailio - Load Balancing Load Balancers
Kamailio - Load Balancing Load BalancersKamailio - Load Balancing Load Balancers
Kamailio - Load Balancing Load Balancers
 
Plan 9: Not (Only) A Better UNIX
Plan 9: Not (Only) A Better UNIXPlan 9: Not (Only) A Better UNIX
Plan 9: Not (Only) A Better UNIX
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
Getting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshopGetting started with SIP Express Media Server SIP app server and SBC - workshop
Getting started with SIP Express Media Server SIP app server and SBC - workshop
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
MiVoice Business software versions through time
MiVoice Business software versions through timeMiVoice Business software versions through time
MiVoice Business software versions through time
 
libuv, NodeJS and everything in between
libuv, NodeJS and everything in betweenlibuv, NodeJS and everything in between
libuv, NodeJS and everything in between
 
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH DeploymentThree Ways Kamailio Can Help Your FreeSWITCH Deployment
Three Ways Kamailio Can Help Your FreeSWITCH Deployment
 
Troubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issuesTroubleshooting common oslo.messaging and RabbitMQ issues
Troubleshooting common oslo.messaging and RabbitMQ issues
 
So You Want to Write a Connector?
So You Want to Write a Connector? So You Want to Write a Connector?
So You Want to Write a Connector?
 

Viewers also liked

Sistema de Mensajeria de Colas con ZeroMQ y Python
Sistema de Mensajeria de Colas con ZeroMQ y PythonSistema de Mensajeria de Colas con ZeroMQ y Python
Sistema de Mensajeria de Colas con ZeroMQ y PythonErnesto Crespo
 
Introduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkIntroduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkMahmoud Said
 
Software Architecture over ZeroMQ
Software Architecture over ZeroMQSoftware Architecture over ZeroMQ
Software Architecture over ZeroMQpieterh
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQpieterh
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characterspieterh
 
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 ZeroMQRobin Xiao
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
Saltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencySaltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencyThomas Jackson
 
Revolutionary Open Source
Revolutionary Open SourceRevolutionary Open Source
Revolutionary Open Sourcepieterh
 
Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012pieterh
 
Switch or broker
Switch or brokerSwitch or broker
Switch or brokerpieterh
 
Git Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, ScalableGit Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, Scalablepieterh
 
WTF Is Messaging And Why You Should Use It?
WTF Is Messaging And Why You Should Use It?WTF Is Messaging And Why You Should Use It?
WTF Is Messaging And Why You Should Use It?James Russell
 
Social architecture-101
Social architecture-101Social architecture-101
Social architecture-101pieterh
 
Fosdem 2009
Fosdem 2009Fosdem 2009
Fosdem 2009pieterh
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanIssac Goldstand
 
Introduction to ZeroMQ
Introduction to ZeroMQIntroduction to ZeroMQ
Introduction to ZeroMQYiHung Lee
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQLuke Luo
 

Viewers also liked (20)

Sistema de Mensajeria de Colas con ZeroMQ y Python
Sistema de Mensajeria de Colas con ZeroMQ y PythonSistema de Mensajeria de Colas con ZeroMQ y Python
Sistema de Mensajeria de Colas con ZeroMQ y Python
 
Introduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalkIntroduction to ZeroMQ - eSpace TechTalk
Introduction to ZeroMQ - eSpace TechTalk
 
Software Architecture over ZeroMQ
Software Architecture over ZeroMQSoftware Architecture over ZeroMQ
Software Architecture over ZeroMQ
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQ
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characters
 
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
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Saltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrencySaltconf 2016: Salt stack transport and concurrency
Saltconf 2016: Salt stack transport and concurrency
 
Revolutionary Open Source
Revolutionary Open SourceRevolutionary Open Source
Revolutionary Open Source
 
Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012Software Architecture using ZeroMQ - techmesh 2012
Software Architecture using ZeroMQ - techmesh 2012
 
Switch or broker
Switch or brokerSwitch or broker
Switch or broker
 
Git Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, ScalableGit Without Branches - Simple, Smooth, Scalable
Git Without Branches - Simple, Smooth, Scalable
 
WTF Is Messaging And Why You Should Use It?
WTF Is Messaging And Why You Should Use It?WTF Is Messaging And Why You Should Use It?
WTF Is Messaging And Why You Should Use It?
 
Social architecture-101
Social architecture-101Social architecture-101
Social architecture-101
 
Fosdem 2009
Fosdem 2009Fosdem 2009
Fosdem 2009
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & Gearman
 
Introduction to Heroku Postgres
Introduction to Heroku PostgresIntroduction to Heroku Postgres
Introduction to Heroku Postgres
 
Introduction to ZeroMQ
Introduction to ZeroMQIntroduction to ZeroMQ
Introduction to ZeroMQ
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
 

Similar to ZeroMQ: Super Sockets - by J2 Labs

Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with phpElizabeth Smith
 
ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!Pedro Januário
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmqRobin Xiao
 
Zmq in context of openstack
Zmq in context of openstackZmq in context of openstack
Zmq in context of openstackYatin Kumbhare
 
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdf
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdfOf the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdf
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdfanuradhasilks
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
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 2011David Troy
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATSThe Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATSApcera
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS NATS
 
The Zen of High Performance Messaging with NATS (Strange Loop 2016)
The Zen of High Performance Messaging with NATS (Strange Loop 2016)The Zen of High Performance Messaging with NATS (Strange Loop 2016)
The Zen of High Performance Messaging with NATS (Strange Loop 2016)wallyqs
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)The World of Smalltalk
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices ArchitectureIdan Fridman
 
Atom The Redis Streams-Powered Microservices SDK: Dan Pipemazo
Atom The Redis Streams-Powered Microservices SDK: Dan PipemazoAtom The Redis Streams-Powered Microservices SDK: Dan Pipemazo
Atom The Redis Streams-Powered Microservices SDK: Dan PipemazoRedis Labs
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 

Similar to ZeroMQ: Super Sockets - by J2 Labs (20)

Socket programming with php
Socket programming with phpSocket programming with php
Socket programming with php
 
ØMQ - An Introduction
ØMQ - An IntroductionØMQ - An Introduction
ØMQ - An Introduction
 
ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!
 
Python networking
Python networkingPython networking
Python networking
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
 
Zmq in context of openstack
Zmq in context of openstackZmq in context of openstack
Zmq in context of openstack
 
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdf
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdfOf the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdf
Of the variedtypes of IPC, sockets arout and awaythe foremostcommon..pdf
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
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
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATSThe Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS
 
The Zen of High Performance Messaging with NATS (Strange Loop 2016)
The Zen of High Performance Messaging with NATS (Strange Loop 2016)The Zen of High Performance Messaging with NATS (Strange Loop 2016)
The Zen of High Performance Messaging with NATS (Strange Loop 2016)
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
Tcpip
TcpipTcpip
Tcpip
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
Ømq & Services @ Chartboost
Ømq & Services @ ChartboostØmq & Services @ Chartboost
Ømq & Services @ Chartboost
 
10 Networking
10 Networking10 Networking
10 Networking
 
Multi user chat system using java
Multi user chat system using javaMulti user chat system using java
Multi user chat system using java
 
Atom The Redis Streams-Powered Microservices SDK: Dan Pipemazo
Atom The Redis Streams-Powered Microservices SDK: Dan PipemazoAtom The Redis Streams-Powered Microservices SDK: Dan Pipemazo
Atom The Redis Streams-Powered Microservices SDK: Dan Pipemazo
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 

Recently uploaded

8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theorydrae5
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)Delhi Call girls
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)Delhi Call girls
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)Delhi Call girls
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morvikas rana
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxpadhand000
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)Delhi Call girls
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 

Recently uploaded (15)

8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptx
 
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 

ZeroMQ: Super Sockets - by J2 Labs

  • 1. ZeroMQ: Super Sockets By James Dennis (@j2labs) http://j2labs.net
  • 2. What is ZeroMQ? Message Passing You still design the payload Fault tolerant A message IS your payload even when broken into multiple packets Many messaging “patterns” offered
  • 3. What is ZeroMQ? Super Sockets Multiple networking protocols(tcp, ipc, whatevz!) Language agnostic (bindings for: ruby, python, java, c, lua, lisp, scheme and more…) Feels like a scripting language for sockets Socket behaviors Round-robin routing Publishing to subscribers Sending job requests
  • 4. What ZeroMQ is not… Persistent reasonably easy to add A message queue there are literally zero mq’s here An out-of-the-box solution instead, it’s easy to build any solution remember, they’re like scripting sockets
  • 5. Socket Types (transports) tcp :: regular TCP sockets socket.connect(“tcp://…”) ipc :: interprocess communication (unix sockets) socket.connect(“ipc://…”) in-proc :: in process communication socket.connect(“in-proc://…”) pgm – pragmatic multicast (or epgmvia udp) socket.connect(“pgm://…”)
  • 6. Socket Behaviors Actually called patterns They exist to make typical cases easy Request-Reply Publish-Subscribe Pipeline Exclusive pair you probably don’t want this
  • 7. Patterns: PUSH/PULL Sends messages to multiple connected hosts Passes messages ROUND ROBIN to connections Blocks PUSH socket if no connections are present N hosts PULL messages from pusher Connect/Remove new hosts as necessary
  • 8. Patterns: PUSH/PULL Server: Sends a message import zmq ctx = zmq.Context() s = ctx.socket(zmq.PUSH) s.bind("ipc://*:5678") while True: s.send(”blablabla") # blocks if no receivers print “Sent one”
  • 9. Patterns: PUSH/PULL Client: Prints messages from server socket import zmq ctx = zmq.Context() s = ctx.socket(zmq.PULL) s.connect("ipc://*:5678") while True: msg = s.recv() print 'Got msg:', msg
  • 10. Patterns: PUSH/PULL A typical worker pipeline looks a bit like this. What’s that PUB/SUB stuff?
  • 11. Patterns: PUB/SUB PUB socket sends topical payloads Can start streaming messages right away ZMQ discards messages if no subscribers exist SUB socket subscribes to “topic” receives all messages reads topic and discards accordingly happens under the hood.
  • 12. Patterns: PUB/ SUB Server: sends messages to `whatevz` s = ctx.socket(zmq.PUB) s.bind("tcp://127.0.0.1:5566") topic = ’whatevz’ message = json.dumps({'msg': 'what up dude?'}) while True: s.send(topic, message) # send to topic print ‘Sent one’
  • 13. Patterns: PUB/SUB Client: demonstrates subscribing to `whatevz` s = ctx.socket(zmq.SUB) s.connect("tcp://127.0.0.1:5566") topic = "whatevz" s.setsockopt(zmq.SUBSCRIBE, topic) # set socket option while True: msg = s.recv() print 'Got msg:’, json.loads(msg)
  • 14. Patterns: REQ/REP One to one messaging Each REQ message must have a REP response Synchronous communication Will error if two REQ’s are sent before one REP
  • 15. Patterns REQ/REP Client context.socket(zmq.REQ) # btw… REQ sockets are blocking! Worker(could say “server”) context.socket(zmq.REP) Multiple Connections One-to-one messaging is useful for workers getting work Basically, pull work request & reply when done Client may need to multiple workers Can’t just open more sockets… we need a new pattern…
  • 16. Patterns: REQ/REP CLIENTsends a “Hello” SERVERsends a “world” back The REQ socket can send a message, but must not send anything else until it gets a response or ZMQ will error. Likewise, a REP socket cannot send a message unless it first received one.
  • 17. Synchronized PUB/SUB Handling “no broker” (aka building one) More than one socket used Like having OneMQ now Hypothetical Communication Order: Subscriber sends sub REQ for topic Publisher REP - “listen <tcp://here>” Subscriber listens to PUB socket
  • 18. Patterns: XREQ/XREP XREQ is a historical name for DEALER A DEALER asynchronously sends to *REP sockets It can send to XREP (aka: ROUTER) sockets too XREP is a historical name for ROUTER A ROUTER asynchronously handles *REQ sockets It can handle DEALER (aka: XREQ) sockets too.
  • 19.
  • 20. ROUTER processes message and sends to some worker via the DEALER
  • 21. DEALERsends message to worker and waits for one response
  • 22. WORKER processes message, sends response back
  • 23. DEALER get message from WORKER, sends along to ROUTER
  • 24. ROUTERgets message and sends back to CLIENT
  • 25.
  • 26. Broker Model: aka “The Titanic”
  • 27. Broker Model with ZMQ Every connection is a REQ socket ROUTER socket to all connections LRU Queue (your broker code!) Up to the LRU Queue handle socket identities properly REQ/REP gets that for free.
  • 28. Flexibility Via Decentralization “ØMQ is like Git(essentially distributed) whereas AMQP is like SVN (essentially centralized)” – James Dennis (me) Welcome From AMQP: http://www.zeromq.org/docs:welcome-from-amqp
  • 29. Mongrel2 (Zed Shaw’s second web server) http://mongrel2.org
  • 30. Brubeck Mongrel2 handler in Python Modeled after Tornado with ideas from Flask / Bottle Uses Eventlet Coroutines! Nonblocking I/O! Uses ZeroMQ Write back end services in any language! Uses DictShield I wrote this too! Database agnostic modeling! ZeroMQ is language agnostic, right?! https://github.com/j2labs/brubeck
  • 31. Try it! https://github.com/j2labs/zmq_examples http://mongrel2.org https://github.com/j2labs/brubeck Read more! http://nichol.as/zeromq-an-introduction http://zguide.zeromq.org/
  • 32. Questions ? James Dennis (@j2labs) jdennis@gmail.com