diff options
| author | C-o-r-E <can.of.tuna@gmail.com> | 2023-07-09 17:29:56 -0400 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2023-08-23 11:20:01 -0700 |
| commit | 52885b6e5af3174e7d367dddcb02b9f50849f191 (patch) | |
| tree | 9866484932e46bac097a3eaf731e9c0e320193fe /demo/pubsub_forwarder/README.adoc | |
| parent | 096ad744e4858136d70eabe0bbd4f6d70d637da2 (diff) | |
| download | nng-52885b6e5af3174e7d367dddcb02b9f50849f191.tar.gz nng-52885b6e5af3174e7d367dddcb02b9f50849f191.tar.bz2 nng-52885b6e5af3174e7d367dddcb02b9f50849f191.zip | |
Add forwarder demo
Diffstat (limited to 'demo/pubsub_forwarder/README.adoc')
| -rw-r--r-- | demo/pubsub_forwarder/README.adoc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/demo/pubsub_forwarder/README.adoc b/demo/pubsub_forwarder/README.adoc new file mode 100644 index 00000000..55832b9a --- /dev/null +++ b/demo/pubsub_forwarder/README.adoc @@ -0,0 +1,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 +---- + + + |
