Content Distribution

We now have a robust framework for creating groups of nodes, letting them chat to each other, and monitoring the resulting network. The next step is to allow them to distribute content as files.

As usual, we’ll aim for the very simplest plausible solution and then improve that step-by-step. At the very least we want the following:

  • An application can tell the Zyre API, “Publish this file,” and provide the path to a file that exists somewhere in the filesystem.

  • Zyre will distribute that file to all peers—both those that are on the network at that time, and those that arrive later.

  • Each time an interface receives a file, it tells its application, “Here is this file.”

We might eventually want more discrimination—e.g., publishing to specific groups—but we can add that later, if it’s needed.

In Chapter 7 we developed a file distribution system (FileMQ) designed to be plugged into ØMQ applications. Let’s use that.

Each node is going to be a file publisher, and a file subscriber. We bind the publisher to an ephemeral port (if we use the standard FileMQ port 5670, we can’t run multiple interfaces on one box), and we broadcast the publisher’s endpoint in the HELLO message, as we did for the log collector. This lets us interconnect all nodes so that all subscribers talk to all publishers.

We need to ensure that each node has its own directory for sending and receiving files (the outbox and the inbox). Again, this is so we can run multiple nodes on one ...

Get ZeroMQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.