Symbolic Links

While using a staging area is a nice, simple API, it also creates costs for senders. If I already have a 2 GB video file on a camera and I want to send it via FileMQ, the current implementation asks that I copy it to a staging area before it will be sent to subscribers.

One option is to mount the whole content directory (e.g., /home/me/Movies), but this is fragile since it means the application can’t decide to send individual files. It’s everything or nothing.

A simple answer is to implement portable symbolic links. As Wikipedia explains:

A symbolic link contains a text string that is automatically interpreted and followed by the operating system as a path to another file or directory. This other file or directory is called the “target”. The symbolic link is a second file that exists independently of its target. If a symbolic link is deleted, its target remains unaffected.

This doesn’t affect the protocol in any way; it’s an optimization in the server implementation. Let’s make a simple portable implementation:

  • A symbolic link consists of a filename with the extension .ln.

  • The filename without .ln is the published filename.

  • The link file contains one line, which is the real path to the file.

Since we’ve collected all operations on files in a single class (fmq_file), it’s a clean change. When we create a new file object we check if it’s a symbolic link; if so, all read-only actions (get file size, read file) operate on the target file, not the link.

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.