Code Connected Volume 1: Learning ZeroMQ

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

"Even connecting a few programs across a few sockets is plain nasty when you start to handle real life situations. Trillions? The cost would be unimaginable. Connecting computers is so difficult that software and services to do this is a multi-billion dollar business. So today we're still connecting applications using raw UDP and TCP, proprietary protocols, HTTP, Websockets. It remains painful, slow, hard to scale, and essentially centralized. To fix the world, we needed to do two things. One, to solve the general problem of "how to connect any code to any code, anywhere". Two, to wrap that up in the simplest possible building blocks that people could understand and use easily. It sounds ridiculously simple. And maybe it is. That's kind of the whole point." If you are a programmer and you aim to build large systems, in any language, then Code Connected is essential reading. Code Connected Volume 1 takes you through learning ZeroMQ, step-by-step, with over 80 examples. You will learn the basics, the API, the different socket types and how they work, reliability, and a host of patterns you can use in your applications. This is the Professional Edition for C/C++.

Author(s): Pieter Hintjens
Edition: 1
Publisher: CreateSpace Independent Publishing Platform
Year: 2013

Language: English
Pages: 318
Tags: ZeroMQ; ØMQ; Sockets; Socket Library; Message-Based Concurrency; Scalable Networking; Clusters Exchanging Messages; Cloud Exchanging Messages; Multithreaded Applications; Messaging Architectures; Request -Reply Pattern; Pub-Sub Pattern

Preface
ØMQ in a Hundred Words
How It Began
The Zen of Zero
How This Book Came To Be
Audience
Code Connected
Chapter 1. Basics
Fixing the World
Starting Assumptions
Getting the Examples
Ask and Ye Shall Receive
A Minor Note on Strings
Version Reporting
Getting the Message Out
Divide and Conquer
Programming with ØMQ
Getting the Context Right
Making a Clean Exit
Why We Needed ØMQ
Socket Scalability
Upgrading from ØMQ v2.2 to ØMQ v3.2
Compatible Changes
Incompatible Changes
Suggested Shim Macros
Warning: Unstable Paradigms!
Chapter 2. Sockets and Patterns
The Socket API
Plugging Sockets into the Topology
Sending and Receiving Messages
Unicast Transports
ØMQ is Not a Neutral Carrier
I/O Threads
Messaging Patterns
High-Level Messaging Patterns
Working with Messages
Handling Multiple Sockets
Multipart Messages
Intermediaries and Proxies
The Dynamic Discovery Problem
Shared Queue (DEALER and ROUTER sockets)
ØMQ’s Built-In Proxy Function
Transport Bridging
Handling Errors and ETERM
Handling Interrupt Signals
Detecting Memory Leaks
Multithreading with ØMQ
Signaling Between Threads (PAIR Sockets)
Node Coordination
Zero-Copy
Pub-Sub Message Envelopes
High-Water Marks
Missing Message Problem Solver
Chapter 3. Advanced Request-Reply Patterns
The Request-Reply Mechanisms
The Simple Reply Envelope
The Extended Reply Envelope
What’s This Good For?
Recap of Request-Reply Sockets
Request-Reply Combinations
The REQ to REP Combination
The DEALER to REP Combination
The REQ to ROUTER Combination
The DEALER to ROUTER Combination
The DEALER to DEALER Combination
The ROUTER to ROUTER Combination
Invalid Combinations
Exploring ROUTER Sockets
Identities and Addresses
ROUTER Error Handling
The Load Balancing Pattern
ROUTER Broker and REQ Workers
ROUTER Broker and DEALER Workers
A Load Balancing Message Broker
A High-Level API for ØMQ
Making a Detour
Features of a Higher-Level API
The CZMQ High-Level API
The Asynchronous Client/Server Pattern
Worked Example: Inter-Broker Routing
Establishing the Details
Architecture of a Single Cluster
Scaling to Multiple Clusters
Federation Versus Peering
The Naming Ceremony
Prototyping the State Flow
Prototyping the Local and Cloud Flows
Putting it All Together
Chapter 4. Reliable Request-Reply Patterns
What is “Reliability”?
Designing Reliability
Client-Side Reliability (Lazy Pirate Pattern)
Basic Reliable Queuing (Simple Pirate Pattern)
Robust Reliable Queuing (Paranoid Pirate Pattern)
Heartbeating
Shrugging It Off
One-Way Heartbeats
Ping-Pong Heartbeats
Heartbeating for Paranoid Pirate
Contracts and Protocols
Service-Oriented Reliable Queuing (Majordomo Pattern)
Asynchronous Majordomo Pattern
Service Discovery
Idempotent Services
Disconnected Reliability (Titanic Pattern)
High-Availability Pair (Binary Star Pattern)
Detailed Requirements
Preventing Split-Brain Syndrome
Binary Star Implementation
Binary Star Reactor
Brokerless Reliability (Freelance Pattern)
Model One: Simple Retry and Failover
Model Two: Brutal Shotgun Massacre
Model Three: Complex and Nasty
Conclusion
Chapter 5. Advanced Pub-Sub Patterns
Pros and Cons of Pub-Sub
Pub-Sub Tracing (Espresso Pattern)
Last Value Caching
Slow Subscriber Detection (Suicidal Snail Pattern)
High-Speed Subscribers (Black Box Pattern)
Reliable Pub-Sub (Clone Pattern)
Centralized Versus Decentralized
Representing State as Key-Value Pairs
Getting an Out-of-Band Snapshot
Republishing Updates from Clients
Working with Subtrees
Ephemeral Values
Using a Reactor
Adding the Binary Star Pattern for Reliability
The Clustered Hashmap Protocol
Building a Multithreaded Stack and API
Postface
Tales from Out There
Rob Gagnon’s Story
Tom van Leeuwen’s Story
Michael Jakl’s Story
Vadim Shalts’s Story
How This Book Happened
Removing Friction
Licensing
Code Connected Volume 2