Initial Design Cut: The API
Hereâs the way I see the first design. FileMQ has to be distributed, so every node can be a server and a client at the same time. But I donât want the protocol to be symmetrical, because that seems forced. We have a natural flow of files from point A to point B, where A is the âserverâ and B is the âclient.â If files flow back the other way, we have two flows. FileMQ is not yet a directory synchronization protocol, but weâll bring it quite close.
Thus, Iâm going to build FileMQ as two pieces: a client and a
server. Then, Iâll put these together in a main application (the
âfilemqâ tool) that can act both as client and server. The two pieces
will look quite similar to the nom_server
, with the
same kind of API:
fmq_server_t
*
server
=
fmq_server_new
();
fmq_server_bind
(
server
,
"tcp://*:5670"
);
fmq_server_publish
(
server
,
"/home/ph/filemq/share"
,
"/public"
);
fmq_server_publish
(
server
,
"/home/ph/photos/stream"
,
"/photostream"
);
fmq_client_t
*
client
=
fmq_client_new
();
fmq_client_connect
(
client
,
"tcp://pieter.filemq.org:5670"
);
fmq_client_subscribe
(
server
,
"/public/"
,
"/home/ph/filemq/share"
);
fmq_client_subscribe
(
server
,
"/photostream/"
,
"/home/ph/photos/stream"
);
while
(
!
zctx_interrupted
)
sleep
(
1
);
fmq_server_destroy
(
&
server
);
fmq_client_destroy
(
&
client
);
If we wrap this C API in other languages, we can easily script FileMQ, embed it applications, port it to smartphones, and so on.
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.