Networking Reference
In-Depth Information
Having reliability in the request-reply pattern is relatively easier than in the
publish-subscribe pattern. We could simply retry sending the message if we
have not received a reply yet. If we still do not get a reply after trying a number
of times, we could discard the communication.
Heartbeating is a layer that can be used to detect if a worker has died or is alive.
However, it should not be used with the request-reply pattern. Heartbeating travels
asynchronously between resources.
If there are a limited number of subscribers connected to the publisher then TCP
is fine, whereas if there are massive number of subscribers, in that case, it would
be a better idea to use PGM.
Slow subscribers in a publish-subscribe
A serious issue of the publish-subscribe pattern is slow subscribers. A lawless
environment would be one where the publisher sends messages to the subscriber at
full speed, but this is utopia. In reality, subscribers cannot keep up with the publisher
most of the time. They are either poorly implemented, have network issues, or some
other reason.
Let's consider the following example where the subscriber runs slower and we abort
the program. First, let's look at the server code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include "zmq.h"
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
void* publisher = zmq_socket(context, ZMQ_PUB);
printf("Starting Server...\n");
zmq_bind(publisher, "tcp://*:4040");
for(;;) {
time_t current_time = time(NULL) % 86400;
char str[11];
snprintf(str, sizeof str, "%lu", current_time);
int s_len = strlen(str);
Search MirCeyron ::

Custom Search