Any network is more than the sum of its parts—it’s the sum of its parts and all of the interactions between parts.
This chapter focuses on those interactions. Specifically, you’ll learn different ways that Node.js microservices communicate.
Connecting these services will expose you to the following aspects of Node.js development:
Node.js is single-threaded, but you can still take advantage of multiple cores or processors by running more processes. In this chapter, you’ll use Node.js’s cluster module to create and manage a pool of Node.js workers.
Microservice endpoints can have many roles and communicate in many ways. We’ll explore powerful messaging patterns like publish/subscribe, request/reply, and push/pull. These patterns appear often in networked application design; you’ll be a better programmer knowing when and how to apply them.
Functions in JavaScript are variadic, meaning they can be called with any number of arguments, whether you planned to receive them or not. You’ll learn how to use JavaScript’s rest parameter syntax to capture arbitrary arguments passed to your functions.
npm is an integral part of the Node.js ecosystem. You’ll learn how to use and manage modules provided through npm. Sometimes modules have external dependencies beyond npm; you’ll learn how to build those, too.
To connect our microservices in this chapter, we’ll use a cross-platform library called ØMQ (pronounced “Zero-M-Q”). The MQ stands for message queue. ØMQ provides high-scalability, low-latency messaging. With its event-loop-based development model, ØMQ and Node.js go together like peanut butter and jelly.
After installing ØMQ, we’ll take it for a spin by making improved versions of some of the services we developed in previous chapters. Then we’ll quickly move on to new messaging patterns.
Let’s get to it!