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)

How to handle interruptions


You need to close the applications properly when you interrupt your application with signals such as SIGTERM or SIGINT. SIGTERM is one of the POSIX signals that sends a signal to a process to end it. Signals are asynchronous and are vulnerable to race conditions.

  • SIGTERM: When you execute the kill command with its defaults in a Unix system, you are basically calling a SIGTERM signal to the denoted process. These signals should be handled properly so your application can release the resources or close database connections and flush the messages properly.

  • SIGINT: This signal can be caught by the application just like SIGTERM as well. The user usually calls it with Ctrl + C.

  • SIGKILL: This is the signal that is called with a kill -9 command. However, this signal cannot be caught by an application, so there is nothing much we could do about it.

SIGINT could be caught in languages that support exception handling by throwing the proper exception such as KeyboardInterrupt...