SlideShare a Scribd company logo
1 of 23
Download to read offline
Network Connected
Development with ZeroMQ
1
June 13, 2019
About ICS
2
Delivering Smart Devices for a Connected World
● Founded in 1987
● Largest source of independent Qt expertise in North America
● Trusted Qt Service Partner since 2002
● Exclusive Open Enrollment Training Partner in North America
● Provides integrated custom software development and user experience
(UX) design
● Embedded, touchscreen, mobile and desktop applications
● HQ in Waltham, MA with offices in California, Canada, Europe
3
In today’s world everything is communicating, exchanging
messages of some form.
What to use as communication platform is an important choice
that will determine the architecture of your application.
From simple two way communication to complex multi node
architectures, 0MQ helps in providing a safe, fast and reliable
communication medium.
Introduction
4
1. What is 0MQ?
2. Why 0MQ?
3. Universal nature of 0MQ
4. 0MQ patterns overview
5. REQ-REP pattern
6. PUB-SUB pattern
7. Router-Dealer pattern
8. 0MQ and Qt
9. 0MQ and alternatives
10. References
11. Advanced patterns
Agenda
5
ZeroMQ is an embeddable networking library.
It gives you sockets that carry atomic messages across
various transports like in-process, inter-process, TCP, and
multicast.
It has a score of language APIs and runs on most operating
systems
It is open source under LGPLv3 license
What is 0MQ
6
● It handles I/O asynchronously. Concurrent 0MQ applications need no locks or
semaphores
● Component come and go dynamically, 0MQ reconnects them automatically
● It queues message automatically when needed and does it intelligently
● It has way dealing with over full queues ( “high water mark” )
● Supports multiple transports - TCP, multi-cast, in-process, interprocess
● It handles slow/blocked readers safely depending on messaging pattern
● It lets you to route messages using variety of patterns
● It lets you to create proxies to queue, forward and capture messages with single
call
● It delivers messages exactly as it sent
● It does not impose any format on messages
Why 0MQ
7
● Written on C++
● Community officially supports CZMQ(C/C++),
JeroMQ(Java), NetMQ(.Net)
● Supports every modern language and platform
● Works in any architecture - centralized or distributed, small
or large
● 40+ language bindings - Ada, Fortran-77, LabView,
Node.js, Python, Swift, Obj-C, Ruby, Smalltalk, Tcl, etc
Universal Nature of 0MQ
8
● Dealer
● Router
● Push
● Pull
● Pair
0MQ offers sockets intended as “building blocks” that we can combine
in nearly any combination to match our architectural needs.
● Request
● Reply
● Publisher
● Subscriber
● XPub
● XSub
0MQ Patterns Overview
9
● Synchronous
● Basic send-receive
capabilities
● REQ: send then recv
● REP: recv then send
REQ - REP Pattern
10
REQ - REP Example
11
0MQ - MacOS/iOS/Swift
12
● Asynchronous
● SUB will lose initial messages
after connection - slow joiner
syndrome
● SUB needs to register to a channel to
start receiving
● SUB can connect to multiple PUB
● PUB has the queue
PUB - SUB pattern
13
#
# Weather update server
# Binds PUB socket to tcp://*:5556
# Publishes random weather updates
#
import zmq
from random import randrange
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5556")
while True:
zipcode = randrange(1, 100000)
temperature = randrange(-80, 135)
relhumidity = randrange(10, 60)
socket.send_string("%i %i %i" %
(zipcode, temperature, relhumidity))
#
# Weather update client
# Connects SUB socket to tcp://localhost:5556
#
import sys
import zmq
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:5556")
# Subscribe to zipcode, default is NYC, 10001
zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
# Python 2 - ascii bytes to unicode str
if isinstance(zip_filter, bytes):
zip_filter = zip_filter.decode('ascii')
socket.setsockopt_string(zmq.SUBSCRIBE, zip_filter)
# Process 5 updates
total_temp = 0
for update_nbr in range(5):
string = socket.recv_string()
zipcode, temperature, relhumidity = string.split()
total_temp += int(temperature)
print("Average temperature for zipcode '%s' was %dF" % (
zip_filter, total_temp / (update_nbr+1))
)
PUB - SUB Example
14
● Asynchronous
● Dealer is an asynchronous REQ
● Router is an asynchronous REP
● Automatic routing handling
● Can be automatically proxied
together
● Use Extended Envelope
Dealer - Router Pattern
15
Building a basic file transfer protocol using only a dealer and a router
● Option #1:
Dealer sends request for a file, Router sends the file serialized
● Option #2:
Dealer sends request for a chunk of a file, Router sends that chunk -
repeat
● Option #3:
Dealer asks for the max amount of chunks that can handle, Router
sends multiple chunks - repeat
Dealer - Router Pattern
16
Building a basic file transfer protocol using only a dealer and a router
Option #1:
Dealer sends request for a file, Router sends the file serialized
Issues:
● Running out of memory
● Router side to load the entire file
● Dealer side to receive the entire file
Solution:
Set a high water mark on the dealer to avoid to run out of memory
Dealer - Router Pattern
17
Building a basic file transfer protocol using only a dealer and a router
Option #2:
Dealer sends request for a chunk of a file, Router sends that chunk -
repeat
Issues:
Slow - too much overhead
Solution:
Reduce overhead :-)
Dealer - Router Pattern
18
Building a basic file transfer protocol using only a dealer and a router
Option #3:
Dealer asks for the max amount of chunks that can handle, Router
sends multiple chunks - repeat
Pro:
No need for HWM
No need for delays/sleep
Fully recoverable
Fast
Dealer - Router Pattern
19
● No official binding - there were various attempt but none is
maintained AFAIK.
● Use QTimers to handle polling
● Set QTimer::timeout and poll::timeout to reasonable values for
your application
● Move your class out of the UI thread
● Isolate 0MQ logic from app logic
0MQ and Qt
20
● nanomsg and nng - https://nanomsg.github.io/nng/
● Developed by Garrett D’Amore and Martin Sustrik of 0MQ
● MIT license vs LGPL3
● Pluggable transport
● Written on C (0MQ is C++)
● POSIX compliant
0MQ and Alternatives
21
ZGuide: http://zguide.zeromq.org
FileMQ: https://github.com/zeromq/filemq
cppzmq: https://github.com/zeromq/cppzmq
libzmq: https://github.com/zeromq/libzmq
ICS Articles: https://www.ics.com/blog/build-high-performance-messaging-service-qt-and-ios
https://www.ics.com/blog/lets-build-zeromq-library
References
22
Advanced Patterns - Pipeline
PUSH-PULL:
● PUSH sockets publish “tasks”
● PULL sockets reads “tasks”
● PUSH sockets distribute the loads between
PULL sockets
● PULL reads fairly between multiple PUSH
23
Simple envelope and extended envelope

More Related Content

What's hot

What's hot (20)

What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Interview preparation workshop
Interview preparation workshopInterview preparation workshop
Interview preparation workshop
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Golang Template
Golang TemplateGolang Template
Golang Template
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQ
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
HKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP WorkshopHKG18-318 - OpenAMP Workshop
HKG18-318 - OpenAMP Workshop
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
TCP/IP
TCP/IPTCP/IP
TCP/IP
 
Early Software Development through Palladium Emulation
Early Software Development through Palladium EmulationEarly Software Development through Palladium Emulation
Early Software Development through Palladium Emulation
 

Similar to Network-Connected Development with ZeroMQ

Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDNTech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
nvirters
 
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Benjamin Cabé
 
Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications
WSO2
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
Andy Piper
 
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
Benjamin Cabé
 

Similar to Network-Connected Development with ZeroMQ (20)

Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
Cotopaxi - IoT testing toolkit (Black Hat Asia 2019 Arsenal)
 
DevCon 5 (July 2013) - WebSockets
DevCon 5 (July 2013) - WebSocketsDevCon 5 (July 2013) - WebSockets
DevCon 5 (July 2013) - WebSockets
 
MQTT enabling the smallest things
MQTT enabling the smallest thingsMQTT enabling the smallest things
MQTT enabling the smallest things
 
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDNTech Tutorial by Vikram Dham: Let's build MPLS router using SDN
Tech Tutorial by Vikram Dham: Let's build MPLS router using SDN
 
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
Using Eclipse and Lua for the Internet of Things - EclipseDay Googleplex 2012
 
APIs at the Edge
APIs at the EdgeAPIs at the Edge
APIs at the Edge
 
Low Latency Mobile Messaging using MQTT
Low Latency Mobile Messaging using MQTTLow Latency Mobile Messaging using MQTT
Low Latency Mobile Messaging using MQTT
 
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorialPowering your next IoT application with MQTT - JavaOne 2014 tutorial
Powering your next IoT application with MQTT - JavaOne 2014 tutorial
 
Open source building blocks for the Internet of Things - Jfokus 2013
Open source building blocks for the Internet of Things - Jfokus 2013Open source building blocks for the Internet of Things - Jfokus 2013
Open source building blocks for the Internet of Things - Jfokus 2013
 
Pushing Data from S7-1200 to Cloud
Pushing Data from S7-1200 to CloudPushing Data from S7-1200 to Cloud
Pushing Data from S7-1200 to Cloud
 
Securing IoT Applications
Securing IoT Applications Securing IoT Applications
Securing IoT Applications
 
Messaging for the Internet of Awesome Things
Messaging for the Internet of Awesome ThingsMessaging for the Internet of Awesome Things
Messaging for the Internet of Awesome Things
 
Node home automation with Node.js and MQTT
Node home automation with Node.js and MQTTNode home automation with Node.js and MQTT
Node home automation with Node.js and MQTT
 
Introducing MQTT
Introducing MQTTIntroducing MQTT
Introducing MQTT
 
javanetworking
javanetworkingjavanetworking
javanetworking
 
Introduction MQTT in English
Introduction MQTT in EnglishIntroduction MQTT in English
Introduction MQTT in English
 
Protocol and Integration Challenges for SDN
Protocol and Integration Challenges for SDNProtocol and Integration Challenges for SDN
Protocol and Integration Challenges for SDN
 
Home automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technologyHome automation using IoT and AWS Cloud technology
Home automation using IoT and AWS Cloud technology
 
Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
Using Eclipse and Lua for the Internet of Things with Eclipse Koneki, Mihini ...
 

More from ICS

Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
ICS
 

More from ICS (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoT
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 

Network-Connected Development with ZeroMQ

  • 1. Network Connected Development with ZeroMQ 1 June 13, 2019
  • 2. About ICS 2 Delivering Smart Devices for a Connected World ● Founded in 1987 ● Largest source of independent Qt expertise in North America ● Trusted Qt Service Partner since 2002 ● Exclusive Open Enrollment Training Partner in North America ● Provides integrated custom software development and user experience (UX) design ● Embedded, touchscreen, mobile and desktop applications ● HQ in Waltham, MA with offices in California, Canada, Europe
  • 3. 3 In today’s world everything is communicating, exchanging messages of some form. What to use as communication platform is an important choice that will determine the architecture of your application. From simple two way communication to complex multi node architectures, 0MQ helps in providing a safe, fast and reliable communication medium. Introduction
  • 4. 4 1. What is 0MQ? 2. Why 0MQ? 3. Universal nature of 0MQ 4. 0MQ patterns overview 5. REQ-REP pattern 6. PUB-SUB pattern 7. Router-Dealer pattern 8. 0MQ and Qt 9. 0MQ and alternatives 10. References 11. Advanced patterns Agenda
  • 5. 5 ZeroMQ is an embeddable networking library. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast. It has a score of language APIs and runs on most operating systems It is open source under LGPLv3 license What is 0MQ
  • 6. 6 ● It handles I/O asynchronously. Concurrent 0MQ applications need no locks or semaphores ● Component come and go dynamically, 0MQ reconnects them automatically ● It queues message automatically when needed and does it intelligently ● It has way dealing with over full queues ( “high water mark” ) ● Supports multiple transports - TCP, multi-cast, in-process, interprocess ● It handles slow/blocked readers safely depending on messaging pattern ● It lets you to route messages using variety of patterns ● It lets you to create proxies to queue, forward and capture messages with single call ● It delivers messages exactly as it sent ● It does not impose any format on messages Why 0MQ
  • 7. 7 ● Written on C++ ● Community officially supports CZMQ(C/C++), JeroMQ(Java), NetMQ(.Net) ● Supports every modern language and platform ● Works in any architecture - centralized or distributed, small or large ● 40+ language bindings - Ada, Fortran-77, LabView, Node.js, Python, Swift, Obj-C, Ruby, Smalltalk, Tcl, etc Universal Nature of 0MQ
  • 8. 8 ● Dealer ● Router ● Push ● Pull ● Pair 0MQ offers sockets intended as “building blocks” that we can combine in nearly any combination to match our architectural needs. ● Request ● Reply ● Publisher ● Subscriber ● XPub ● XSub 0MQ Patterns Overview
  • 9. 9 ● Synchronous ● Basic send-receive capabilities ● REQ: send then recv ● REP: recv then send REQ - REP Pattern
  • 10. 10 REQ - REP Example
  • 12. 12 ● Asynchronous ● SUB will lose initial messages after connection - slow joiner syndrome ● SUB needs to register to a channel to start receiving ● SUB can connect to multiple PUB ● PUB has the queue PUB - SUB pattern
  • 13. 13 # # Weather update server # Binds PUB socket to tcp://*:5556 # Publishes random weather updates # import zmq from random import randrange context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind("tcp://*:5556") while True: zipcode = randrange(1, 100000) temperature = randrange(-80, 135) relhumidity = randrange(10, 60) socket.send_string("%i %i %i" % (zipcode, temperature, relhumidity)) # # Weather update client # Connects SUB socket to tcp://localhost:5556 # import sys import zmq # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect("tcp://localhost:5556") # Subscribe to zipcode, default is NYC, 10001 zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001" # Python 2 - ascii bytes to unicode str if isinstance(zip_filter, bytes): zip_filter = zip_filter.decode('ascii') socket.setsockopt_string(zmq.SUBSCRIBE, zip_filter) # Process 5 updates total_temp = 0 for update_nbr in range(5): string = socket.recv_string() zipcode, temperature, relhumidity = string.split() total_temp += int(temperature) print("Average temperature for zipcode '%s' was %dF" % ( zip_filter, total_temp / (update_nbr+1)) ) PUB - SUB Example
  • 14. 14 ● Asynchronous ● Dealer is an asynchronous REQ ● Router is an asynchronous REP ● Automatic routing handling ● Can be automatically proxied together ● Use Extended Envelope Dealer - Router Pattern
  • 15. 15 Building a basic file transfer protocol using only a dealer and a router ● Option #1: Dealer sends request for a file, Router sends the file serialized ● Option #2: Dealer sends request for a chunk of a file, Router sends that chunk - repeat ● Option #3: Dealer asks for the max amount of chunks that can handle, Router sends multiple chunks - repeat Dealer - Router Pattern
  • 16. 16 Building a basic file transfer protocol using only a dealer and a router Option #1: Dealer sends request for a file, Router sends the file serialized Issues: ● Running out of memory ● Router side to load the entire file ● Dealer side to receive the entire file Solution: Set a high water mark on the dealer to avoid to run out of memory Dealer - Router Pattern
  • 17. 17 Building a basic file transfer protocol using only a dealer and a router Option #2: Dealer sends request for a chunk of a file, Router sends that chunk - repeat Issues: Slow - too much overhead Solution: Reduce overhead :-) Dealer - Router Pattern
  • 18. 18 Building a basic file transfer protocol using only a dealer and a router Option #3: Dealer asks for the max amount of chunks that can handle, Router sends multiple chunks - repeat Pro: No need for HWM No need for delays/sleep Fully recoverable Fast Dealer - Router Pattern
  • 19. 19 ● No official binding - there were various attempt but none is maintained AFAIK. ● Use QTimers to handle polling ● Set QTimer::timeout and poll::timeout to reasonable values for your application ● Move your class out of the UI thread ● Isolate 0MQ logic from app logic 0MQ and Qt
  • 20. 20 ● nanomsg and nng - https://nanomsg.github.io/nng/ ● Developed by Garrett D’Amore and Martin Sustrik of 0MQ ● MIT license vs LGPL3 ● Pluggable transport ● Written on C (0MQ is C++) ● POSIX compliant 0MQ and Alternatives
  • 21. 21 ZGuide: http://zguide.zeromq.org FileMQ: https://github.com/zeromq/filemq cppzmq: https://github.com/zeromq/cppzmq libzmq: https://github.com/zeromq/libzmq ICS Articles: https://www.ics.com/blog/build-high-performance-messaging-service-qt-and-ios https://www.ics.com/blog/lets-build-zeromq-library References
  • 22. 22 Advanced Patterns - Pipeline PUSH-PULL: ● PUSH sockets publish “tasks” ● PULL sockets reads “tasks” ● PUSH sockets distribute the loads between PULL sockets ● PULL reads fairly between multiple PUSH
  • 23. 23 Simple envelope and extended envelope