Article Directory
- 1 Overview
- 2. Download and install
- 3. Usage mode
-
- 3.1. Overview
- 3.2.Pipeline (A One-Way Pipe)
- 3.3. Request/Reply (I ask, you answer) request/reply (I ask, you answer)
- 3.4.Pair (Two Way Radio)
- 3.5. Pub/Sub (Topics & Broadcast) Publish/Subscribe (Topics and Broadcast)
- 3.6.Survey (Everybody Votes) survey (everybody voted)
- 3.7. Bus (Routing) Bus (Routing)
- 4 Official website address of sample code for each mode
1 Overview
The nanomsg library is a simple high-performance implementation of several "scalability protocols". These scalability protocols are lightweight messaging protocols that can be used to solve many very common messaging modes, such as request/response, publish/subscribe, measurer/responder, etc. These protocols can run on various transmissions, such as TCP, UNIX sockets, and even WebSocket.
2. Download and install
2.1. Download address
https://github.com/nanomsg/nanomsg
current version: 1.1.5, released on October 15, 2018.
2.2 POSIX (Linux, MacOS X, UNIX) installation preparation
ANSI C compiler supporting C89
POSIX pthreads (should be present on all modern POSIX systems)
BSD sockets support for both TCP and UNIX domain sockets
CMake (http://cmake.org) 2.8.7 or newer, available in $PATH as cmake
2.2.4. Ubuntu compilation
Install cmake
sudo snap install cmake (sudo snap install cmake --classic)
official description of the compilation steps
md build
cd build
cmake ..
cmake --build . --config Debug
ctest -C Debug .
sudo cmake --build . --config Debug --target install
Note, adjust the installation path method:
chmod 777 configure
./configure --prefix=/home/share/linuxlib/nanomsg
3. Usage mode
3.1. Overview
Pipeline (A One-Way Pipe)
Request/Reply (I ask, you answer) Request/Reply (I ask, you answer)
Pair (Two Way Radio)
Pub/Sub (Topics) & Broadcast) Publish/Subscribe (topic and broadcast)
Survey (Everybody Votes ) Survey (Everybody Votes)
Bus (Routing)
Example of how to use the Bus (Routing) : https://nanomsg.org/gettingstarted/index.html#
3.2.Pipeline (A One-Way Pipe)
3.2.1. Mode
This mode is very useful for solving producer/consumer problems (including load balancing). The message flows from the push side to the pull side. If multiple peers are connected, the mode will try to distribute fairly.
3.3. Request/Reply (I ask, you answer) request/reply (I ask, you answer)
3.3.1. Mode
Request/response is used for synchronous communication. In synchronous communication, each question is responded with a single response, such as remote procedure call (rpc). Like pipelines, it can also perform load balancing. This is the only reliable messaging mode in the suite, because if the request does not match the response, it will automatically retry.
3.4.Pair (Two Way Radio)
3.4.1. Mode
When there is a one-to-one relationship, use the pair mode. Only one peer can be connected to another peer at a time, but both peers can speak freely.
3.5. Pub/Sub (Topics & Broadcast) Publish/Subscribe (Topics and Broadcast)
3.5.1. Mode
This mode is used to allow a single broadcaster to publish messages to multiple subscribers, and subscribers can choose to limit the messages they receive.
3.6.Survey (Everybody Votes) survey (everybody voted)
3.6.1. Mode
The surveyor mode is used to send timeout measurements, and a response is returned separately before the end of the measurement. This mode is very useful for service discovery and voting algorithms.
3.7. Bus (Routing) Bus (Routing)
3.7.1. Mode
The bus protocol is very useful for routing applications or building fully interconnected mesh networks. In this mode, messages are sent to each directly connected peer.
4 Official website address of sample code for each mode
https://nanomsg.org/gettingstarted