aboutsummaryrefslogtreecommitdiff
path: root/demo/pubsub_forwarder/README.adoc
blob: 55832b9a176d56cca91e70de6c103d44bc29ab5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
= PubSub Forwarder

This is a trivial example of a forwarder/proxy for the pub/sub pattern.

The concept is as follows: the forwarder will listen for connections on
both a front-end port and a back-end port. The front-end will act as a 
subscriber so that publishers can publish to it. The back-end will act
as a publisher so that subscribers can subscribe to it. The front-end 
then forwards to the back end.

== Compiling

CMake with ninja-build is simplest:

[source, bash]
----
cmake -GNinja -B build
cd build
ninja
----

Or if you prefer a traditional approach, 
the following is an example typical of UNIX and similar systems like
Linux and macOS may appeal:

[source, bash]
----
export CPPFLAGS="-I /usr/local/include"
export LDFLAGS="-L /usr/local/lib -lnng"
export CC="cc"
${CC} ${CPPFLAGS} pubsub_forwarder.c -o pubsub_forwarder ${LDFLAGS}
----

== Running

An example setup for running this example would involve the following:

. Step 1: Run this example binary (in the background or a terminal, etc)
. Step 2: In a new terminal, run the following

[source, bash]
----
nngcat --sub --dial "tcp://localhost:3328" --quoted
----

. Step 3: In a second terminal, run the same command again to give us two subscribers

[source, bash]
----
nngcat --sub --dial "tcp://localhost:3328" --quoted
----


. In a third terminal, run the following to publish a counter

[source, bash]
----
for n in $(seq 0 99); do nngcat --pub --dial "tcp://localhost:3327" --data "$n"; done
----