SlideShare une entreprise Scribd logo
1  sur  30
https://github.com/soggie/naws
Leveraging ZeroMQ for 
Node.js 
Another tool in your toolbox
About Me 
• Ruben Tan 
• @roguejs (twitter) 
• Works in GrabTaxi (Malaysia) 
github.com/soggie/naws
ZeroMQ 
• “zero” as in none, nada, nil, 無 
• MQ as in Message Queue
Why call ZeroMQ as 
so when it is not a 
message queue?
I know. Wrong meme. Shhh.
• Originally conceived as a stock trading 
messaging solution 
• Moved on to generalizing its purpose 
• Adopted BSD Socket API and semantics 
• Smart end-point, dump network
• ZeroMQ is a networking library with 
message queue semantics 
• Used primarily for connectivity between 
services 
• Can be used to facilitate brokerless 
message passing topologies
Crash Course! 
• Socket basics 
• Buffering (high watermark) 
• Load balancing (outgoing/incoming strategy) 
• PUSH socket 
• PULL socket 
• PUB socket 
• SUB socket 
• We won’t cover: REQ-REP, XPUB-XSUB, ROUTER-DEALER, 
STREAM, PAIR, as well as DEVICES
0MQ Sockets 
• Supports: 
• inproc, IPC, TCP, pgm, epgm 
• Maintains it’s own internal queue 
• High watermark controls buffer size 
• Has a MUTE strategy 
• Has different INCOMING and 
OUTGOING strategies
MUTE 
• Connection states: 
• connect() ==> READY 
• bind() ==> MUTE 
• accept() ==> READY 
• 2 kinds of MUTE state: block or drop
BLOCK
DROP
Exhibit A - REQ-REP 
https://github.com/soggie/naws/tree/master/test/talk/exhibit-a.js
// Bind the REP socket 
reply.bind('inproc://exhibit-a'); 
// Make the REQ socket connect to the REP socket 
request.connect('inproc://exhibit-a'); 
request.on('message', function (msg) { 
console.log('---- recv: ' + msg.toString()); 
}); 
reply.on('message', function (msg) { 
console.log('-- recv: ' + msg.toString()); 
work(); // Some heavy duty work 
reply.send(msg); 
console.log('--- send: ' + msg.toString()); 
}); 
setInterval(function () { 
var msg = color(ran(1000, 1000) + ''); 
console.log('- send: ' + msg); 
request.send(msg); 
}, 1000);
PUSH 
• INCOMING: 
none 
• OUTGOING: 
round-robin 
• MUTE: 
blocks 
PPUUSSHH 
1 2 3 
4 5 6 
AA BB CC
Exhibit B 
https://github.com/soggie/naws/tree/master/test/talk/exhibit-b.js
PULL 
AA BB CC 
1 2 3 
• INCOMING 
fair-queue 
• OUTGOING 
none 
• MUTE 
block (??) PPUULLLL 
4 5 6
Exhibit C 
https://github.com/soggie/naws/tree/master/test/talk/exhibit-c.js
PUB 
• INCOMING 
none 
• OUTGOING 
fan-out 
• MUTE 
drop 
PPUUBB 
1 1 1 
2 2 2 
AA BB CC
Exhibit D 
https://github.com/soggie/naws/tree/master/test/talk/exhibit-d.js
SUB 
PP PP PP 
1 2 3 
• INCOMING 
fair-queue 
• OUTGOING 
none 
• MUTE 
none SSUUBB 
4 5 6
Exhibit E 
https://github.com/soggie/naws/tree/master/test/talk/exhibit-e.js
Let’s Build Something
• A simple HTTP web server on top of 
express 
• Uses worker processes to handle requests 
• Can add or kill workers any time 
• Rudimentary monitoring and reliability
Architecture 
SSUUBB PPUUBB 
RR EExxpprreessss 
PPUUSSHH 
5 
HHaannddlleerr 
PPUULLLL 
1 
2 
3 
4 
6 
8 7 
Server Process Worker Process
Conclusion 
• zeromq is a lightweight networking library 
• build messaging topologies you want 
• nice async features enabling you to do fun 
stuff (add/kill workers) 
• use to connect apps written in different 
languages/tech stacks 
• a very useful tool to have and understand
Similar & References 
• Nanomsg (http://nanomsg.org) 
- Martin Sustrik, fork/rewrite of 0mq 
• Axon (https://github.com/visionmedia/axon) 
- Pure node.js 0mq sockets 
• Theory of ZeroMQ 
http://250bpm.com/concepts 
• ZeroMQ Internal Architecture 
http://www.aosabook.org/en/zeromq.html 
• Dissecting Message Queues 
http://www.bravenewgeek.com/dissecting-message-queues/
THE END 
Questions? 
Questions?

Contenu connexe

Tendances

Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromqDongmin Yu
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmqRobin Xiao
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingLubomir Rintel
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characterspieterh
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQfcrippa
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/awaitC4Media
 
ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!Pedro Januário
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programmingIskren Chernev
 
Skydive, real-time network analyzer
Skydive, real-time network analyzer Skydive, real-time network analyzer
Skydive, real-time network analyzer Sylvain Afchain
 
Skydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSkydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSylvain Afchain
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 

Tendances (20)

Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromq
 
ZeroMQ
ZeroMQZeroMQ
ZeroMQ
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
 
ZeroMQ in PHP
ZeroMQ in PHPZeroMQ in PHP
ZeroMQ in PHP
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
Rust Primer
Rust PrimerRust Primer
Rust Primer
 
CurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious CharactersCurveZMQ, ZMTP and other Dubious Characters
CurveZMQ, ZMTP and other Dubious Characters
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQ
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!ZeroMQ - Sockets on steroids!
ZeroMQ - Sockets on steroids!
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programming
 
Skydive 5/07/2016
Skydive 5/07/2016Skydive 5/07/2016
Skydive 5/07/2016
 
Skydive, real-time network analyzer
Skydive, real-time network analyzer Skydive, real-time network analyzer
Skydive, real-time network analyzer
 
Skydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integrationSkydive, real-time network analyzer, container integration
Skydive, real-time network analyzer, container integration
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
 
Skydive 31 janv. 2016
Skydive 31 janv. 2016Skydive 31 janv. 2016
Skydive 31 janv. 2016
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Scapy talk
Scapy talkScapy talk
Scapy talk
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
 

Similaire à Leveraging zeromq for node.js

introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage SystemsSATOSHI TAGOMORI
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Eugene Yokota
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with serverEugene Yokota
 
Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)Lucas Jellema
 
FOSDEM2018 Janus Lua plugin presentation
FOSDEM2018 Janus Lua plugin presentationFOSDEM2018 Janus Lua plugin presentation
FOSDEM2018 Janus Lua plugin presentationLorenzo Miniero
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Railselliando dias
 
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondBuilding APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondRick G. Garibay
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Engage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-RedEngage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-RedPaul Withers
 

Similaire à Leveraging zeromq for node.js (20)

Stackato v2
Stackato v2Stackato v2
Stackato v2
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Stackato v5
Stackato v5Stackato v5
Stackato v5
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Stackato v3
Stackato v3Stackato v3
Stackato v3
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
Rack
RackRack
Rack
 
Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)
 
Stackato
StackatoStackato
Stackato
 
FOSDEM2018 Janus Lua plugin presentation
FOSDEM2018 Janus Lua plugin presentationFOSDEM2018 Janus Lua plugin presentation
FOSDEM2018 Janus Lua plugin presentation
 
RubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on RailsRubyStack: the easiest way to deploy Ruby on Rails
RubyStack: the easiest way to deploy Ruby on Rails
 
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondBuilding APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Engage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-RedEngage 2019: Introduction to Node-Red
Engage 2019: Introduction to Node-Red
 

Plus de Ruben Tan

Basic distributed systems principles
Basic distributed systems principlesBasic distributed systems principles
Basic distributed systems principlesRuben Tan
 
Demystifying blockchains
Demystifying blockchainsDemystifying blockchains
Demystifying blockchainsRuben Tan
 
Banking on blockchains
Banking on blockchainsBanking on blockchains
Banking on blockchainsRuben Tan
 
Consensus in distributed computing
Consensus in distributed computingConsensus in distributed computing
Consensus in distributed computingRuben Tan
 
Defensive programming in Javascript and Node.js
Defensive programming in Javascript and Node.jsDefensive programming in Javascript and Node.js
Defensive programming in Javascript and Node.jsRuben Tan
 
Client-side storage
Client-side storageClient-side storage
Client-side storageRuben Tan
 
How we git - commit policy and code review
How we git - commit policy and code reviewHow we git - commit policy and code review
How we git - commit policy and code reviewRuben Tan
 
NodeHack #2 - MVP
NodeHack #2 - MVPNodeHack #2 - MVP
NodeHack #2 - MVPRuben Tan
 
40 square's git workflow
40 square's git workflow40 square's git workflow
40 square's git workflowRuben Tan
 
Unit testing for 40 square software
Unit testing for 40 square softwareUnit testing for 40 square software
Unit testing for 40 square softwareRuben Tan
 

Plus de Ruben Tan (10)

Basic distributed systems principles
Basic distributed systems principlesBasic distributed systems principles
Basic distributed systems principles
 
Demystifying blockchains
Demystifying blockchainsDemystifying blockchains
Demystifying blockchains
 
Banking on blockchains
Banking on blockchainsBanking on blockchains
Banking on blockchains
 
Consensus in distributed computing
Consensus in distributed computingConsensus in distributed computing
Consensus in distributed computing
 
Defensive programming in Javascript and Node.js
Defensive programming in Javascript and Node.jsDefensive programming in Javascript and Node.js
Defensive programming in Javascript and Node.js
 
Client-side storage
Client-side storageClient-side storage
Client-side storage
 
How we git - commit policy and code review
How we git - commit policy and code reviewHow we git - commit policy and code review
How we git - commit policy and code review
 
NodeHack #2 - MVP
NodeHack #2 - MVPNodeHack #2 - MVP
NodeHack #2 - MVP
 
40 square's git workflow
40 square's git workflow40 square's git workflow
40 square's git workflow
 
Unit testing for 40 square software
Unit testing for 40 square softwareUnit testing for 40 square software
Unit testing for 40 square software
 

Dernier

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Dernier (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Leveraging zeromq for node.js

  • 2. Leveraging ZeroMQ for Node.js Another tool in your toolbox
  • 3. About Me • Ruben Tan • @roguejs (twitter) • Works in GrabTaxi (Malaysia) github.com/soggie/naws
  • 4.
  • 5. ZeroMQ • “zero” as in none, nada, nil, 無 • MQ as in Message Queue
  • 6. Why call ZeroMQ as so when it is not a message queue?
  • 7. I know. Wrong meme. Shhh.
  • 8. • Originally conceived as a stock trading messaging solution • Moved on to generalizing its purpose • Adopted BSD Socket API and semantics • Smart end-point, dump network
  • 9. • ZeroMQ is a networking library with message queue semantics • Used primarily for connectivity between services • Can be used to facilitate brokerless message passing topologies
  • 10. Crash Course! • Socket basics • Buffering (high watermark) • Load balancing (outgoing/incoming strategy) • PUSH socket • PULL socket • PUB socket • SUB socket • We won’t cover: REQ-REP, XPUB-XSUB, ROUTER-DEALER, STREAM, PAIR, as well as DEVICES
  • 11. 0MQ Sockets • Supports: • inproc, IPC, TCP, pgm, epgm • Maintains it’s own internal queue • High watermark controls buffer size • Has a MUTE strategy • Has different INCOMING and OUTGOING strategies
  • 12. MUTE • Connection states: • connect() ==> READY • bind() ==> MUTE • accept() ==> READY • 2 kinds of MUTE state: block or drop
  • 13. BLOCK
  • 14. DROP
  • 15. Exhibit A - REQ-REP https://github.com/soggie/naws/tree/master/test/talk/exhibit-a.js
  • 16. // Bind the REP socket reply.bind('inproc://exhibit-a'); // Make the REQ socket connect to the REP socket request.connect('inproc://exhibit-a'); request.on('message', function (msg) { console.log('---- recv: ' + msg.toString()); }); reply.on('message', function (msg) { console.log('-- recv: ' + msg.toString()); work(); // Some heavy duty work reply.send(msg); console.log('--- send: ' + msg.toString()); }); setInterval(function () { var msg = color(ran(1000, 1000) + ''); console.log('- send: ' + msg); request.send(msg); }, 1000);
  • 17. PUSH • INCOMING: none • OUTGOING: round-robin • MUTE: blocks PPUUSSHH 1 2 3 4 5 6 AA BB CC
  • 19. PULL AA BB CC 1 2 3 • INCOMING fair-queue • OUTGOING none • MUTE block (??) PPUULLLL 4 5 6
  • 21. PUB • INCOMING none • OUTGOING fan-out • MUTE drop PPUUBB 1 1 1 2 2 2 AA BB CC
  • 23. SUB PP PP PP 1 2 3 • INCOMING fair-queue • OUTGOING none • MUTE none SSUUBB 4 5 6
  • 26. • A simple HTTP web server on top of express • Uses worker processes to handle requests • Can add or kill workers any time • Rudimentary monitoring and reliability
  • 27. Architecture SSUUBB PPUUBB RR EExxpprreessss PPUUSSHH 5 HHaannddlleerr PPUULLLL 1 2 3 4 6 8 7 Server Process Worker Process
  • 28. Conclusion • zeromq is a lightweight networking library • build messaging topologies you want • nice async features enabling you to do fun stuff (add/kill workers) • use to connect apps written in different languages/tech stacks • a very useful tool to have and understand
  • 29. Similar & References • Nanomsg (http://nanomsg.org) - Martin Sustrik, fork/rewrite of 0mq • Axon (https://github.com/visionmedia/axon) - Pure node.js 0mq sockets • Theory of ZeroMQ http://250bpm.com/concepts • ZeroMQ Internal Architecture http://www.aosabook.org/en/zeromq.html • Dissecting Message Queues http://www.bravenewgeek.com/dissecting-message-queues/
  • 30. THE END Questions? Questions?