Book Image

ZeroMQ

By : Faruk Akgul
Book Image

ZeroMQ

By: Faruk Akgul

Overview of this book

<p>ØMQ (also spelled ZeroMQ, 0MQ, or ZMQ) is a high-performance asynchronous messaging library aimed at use in scalable distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ØMQ system can run without a dedicated message broker. The library is designed to have a familiar socket-style API.<br /><br />"ZeroMQ" teaches you to use ZeroMQ through examples in C programming language. You will learn how to use fundamental patterns of message/queuing with a step-by-step tutorial approach and how to apply them. Then, you’ll learn how to use high level APIs and to work with multiple sockets and multithreaded programs through many examples.<br /><br />This book looks at how message/queue works in general and what kinds of problems it solves. Then, it explains how ZeroMQ works and how it differs from other message/queue libraries and how it can be used in different scenarios.<br /><br />You will also learn how to apply essential message/queue design patterns in different scenarios, and how they differ from each other. It shows you practical examples you can apply. You will also learn how to work with multiple sockets.<br /><br />You will learn the basics of ZeroMQ as well as how to use different patterns.</p>
Table of Contents (12 chapters)

Introduction to CZMQ


CZMQ is a high-level C library for ZeroMQ. Its main purpose is to minimize the differences between ZeroMQ v2.x and v3.x and also to enable doing more with less code. If you recall from Chapter 1, Getting Started, we said that the examples are written for ZeroMQ v3.2. Therefore, they may not work with ZeroMQ v2.2 or older.

It includes list and hash structures and lets developers work with strings and multi-part messages easier. It also automatically closes opened sockets when a given context is terminated.

Linking CZMQ with your ZeroMQ application is simple:

gcc –lczmq –o program program.c

zctx

This is a wrapper for the ZeroMQ context. Its main features are as follows:

  • Setting up signal handling, thus blocking calls such as zmq_poll and zmq_recv() and returning when SIGINT (Ctrl + C) or SIGTERM (kill) is called.

  • It automatically closes the opened sockets before terminating the context.

Sample usage:

zctx_t* context = zctx_new();

zstr_send

This is called to send and receive C...