Networking Reference
In-Depth Information
• A subscriber could connect to multiple publishers. Data will be transmitted
via the fair-queue strategy.
• The publisher sends all the messages to all subscribers and filtering is done
on the subscriber's side as we have seen from our stock exchange program
that we provided earlier.
• We will return to the publisher-subscriber pattern in Chapter 4 , Advanced
Patterns , to discuss how to deal with the slow subscribers.
The pipeline pattern
Let's continue with the pipeline pattern. The pipeline pattern transmits data between
nodes ordered in the pipeline. Data is transmitted continuously and each step of the
pipeline is connected to one or more nodes. A round-robin strategy is used to transmit
data between nodes. It is somewhat similar to the request-reply pattern.
The divide and conquer strategy
It is like there is no escape from a divide and conquer strategy when you do
programming. Remember when you enrolled in your algorithms class and your
annoying professor introduced divide and conquer using merge sort and a week
later half of the class dropped the unit? We remember as well. It is a small world
and here is divide and conquer, again.
Let's do something in parallel with ZeroMQ. Consider a scenario where we have a
producer that generates some random numbers. We also have workers, which find
the square root of those numbers with Newton's method. Then we have a collector
that collects the results from the workers.
The following is our server code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "zmq.h"
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
Search MirCeyron ::

Custom Search