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)

Preface

This book is an introductory guide to message queuing components and ZeroMQ. We will cover how you can apply patterns to your applications.

What this book covers

Chapter 1, Getting Started, explains what a message queuing system is, discusses the importance of message queuing, and introduces ZeroMQ to the reader. It also introduces the request-reply pattern with the "hello world" example and shows examples of how to handle string in C and version reporting in ZeroMQ.

Chapter 2, Introduction to Sockets, explores how to use ZeroMQ with sockets by providing example code.

Chapter 3, Using Socket Topology, goes beyond Chapter 2, Introduction to Sockets, and discusses the difference between ZeroMQ sockets and TCP sockets and shows how to use the topics covered in the previous chapters for real-world applications.

Chapter 4, Advanced Patterns, is a brief introduction to more advanced topics and discusses how to use patterns in ZeroMQ applications.

Appendix, contains bibliography and external links.

What you need for this book

To run the examples in the book the following software will be required:

Who this book is for

This book is for developers who are interested in learning and implementing ZeroMQ for their applications. The reader needs to have basic C programming knowledge. Prior ZeroMQ experience is not expected.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "You may use czmq.h which lets C developers to code their ZeroMQ applications easier and shorter."

A block of code is set as follows:

#include <string.h>
#include <stdio.h>
#include "zmq.h"


int main (int argc, char const *argv[]) {
  void* context = zmq_init(1);
  void* request = zmq_socket(context, ZMQ_REQ);
  printf("Connecting to server\n");
  zmq_connect(request, "tcp://localhost:4040");
  
  zmq_close(request);
  zmq_term(context);
  return 0;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

#include <string.h>
#include <stdio.h>
#include "zmq.h"

int main (int argc, char const *argv[]) {
  void* context = zmq_init(1);
  void* request = zmq_socket(context, ZMQ_REQ);
  printf("Connecting to server\n");
  zmq_connect(request, "tcp://localhost:4040");
  
  zmq_close(request);
  zmq_term(context);
  return 0;
}

Any command-line input or output is written as follows:

gcc -Wall -lzmq -o zero zero.c

When we say zmq_socket(2) we mean zmq_socket function takes two parameters. When we say zmq_ctx_new() we mean zmq_ctx_new function does not take any parameters.

New terms and important words are shown in bold.

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.