ZeroMQ
1. ZeroMQ
ZeroMQ is a High-performance Async Messaging Library targeted at distributed and parallel Systems. It defines fundamental Message Patterns and helps easily implement the defined Message Patterns. It also has the advantage of supporting various languages.
1.1. Messaging Pattern
ZeroMQ defines 4 Message Patterns: Request-reply, Pub-sub, Pipeline, and Exclusive pair.
1.1.1. Request-reply
![[Figure 1] Request-reply Sync](/blog-software/docs/theory-analysis/zeromq/images/request-reply-sync.png)
[Figure 1] Request-reply Sync
Request-reply Pattern refers to a general Pattern where Server replies to Client’s Request. Both Sync and Async methods can be implemented with ZeroMQ. [Figure 1] shows the Sync method’s Request-reply Pattern. Clients use REQ Type Socket to send Messages to Server. Server uses REP Type Socket to send received Messages back to Clients.
![[Figure 2] Request-reply Async](/blog-software/docs/theory-analysis/zeromq/images/request-reply-async.png)
[Figure 2] Request-reply Async
[Figure 2] shows the Async method’s Request-reply Pattern. A Broker exists between Server and Client. Broker’s ROUTER Type Socket receives Messages from Client’s REQ Type Socket on behalf of Server. Broker that received Messages sends Messages to Server’s REP Type Socket through DEALER Type Socket.
1.1.2. Pub-sub
![[Figure 3] Pub-sub](/blog-software/docs/theory-analysis/zeromq/images/pub-sub.png)
[Figure 3] Pub-sub
Pub-sub Pattern is a Pattern where Publisher delivers the same Message to all Subscribers. [Figure 3] shows the Pub-sub Pattern. Publisher uses PUB Type Socket to send Messages to all Subscribers. Subscribers use SUB Type Socket to receive Messages. Pub-sub operates in Async method.
1.1.3. Pipeline
![[Figure 4] Push-pull](/blog-software/docs/theory-analysis/zeromq/images/push-pull.png)
[Figure 4] Push-pull
Pipeline Pattern is a parallel processing Pattern that distributes Messages for processing and collects processed Messages again. [Figure 4] shows the Pipeline Pattern. Messages sent from Ventilator’s Push Type Socket are evenly distributed to Workers’ Pull Type Sockets. Conversely, Messages sent from Workers’ Push Type Sockets are collected at Sink’s Pull Type Socket.
1.1.4. Exclusive pair
![[Figure 5] Exclusive pair](/blog-software/docs/theory-analysis/zeromq/images/exclusive-pair.png)
[Figure 5] Exclusive pair
Exclusive pair Pattern is a Pattern used when exchanging Messages between 2 Threads in one Process. [Figure 5] shows the Exclusive pair Pattern among 3 Threads. Only PAIR Type Socket is used.