Creating a Middleware Framework for ZeroMQ

Learn how to create a Middleware Manager for creating a middleware framework for ZeroMQ.

We'll cover the following

Let’s now demonstrate the pattern by building a middleware framework around the ZeroMQ messaging library. ZeroMQ (also known as ZMQ, or ØMQ) provides a simple interface for exchanging atomic messages across the network using a variety of protocols. It shines for its performance, and its basic set of abstractions is specifically built to facilitate the implementation of custom messaging architectures. For this reason, ZeroMQ is often chosen to build complex distributed systems.

The interface of ZeroMQ is pretty low-level because it only allows us to use strings and binary buffers for messages. So, any encoding or custom formatting of data has to be implemented by the users of the library.

In the next example, we’re going to build a middleware infrastructure to abstract the preprocessing and postprocessing of the data passing through a ZeroMQ socket, so that we can transparently work with JSON objects, but also seamlessly compress messages traveling over the wire.

The Middleware Manager

The first step toward building a middleware infrastructure around ZeroMQ is to create a component that’s responsible for executing the middleware pipeline when a new message is received or sent. For this purpose, let’s create a new module called zmqMiddlewareManager.js and let’s define it as follows:

Get hands-on with 1200+ tech skills courses.