“服务器"到“服务器"零MQ通信 [英] "Server" to "Server" ZeroMQ communication
问题描述
我想构建一个具有以下架构的系统:
I want to build a system that has the following architecture:
+------------------+ +------------------+
| App1. 0mq client | <------> | App2. 0mq server |
+------------------+ +------------------+
其中App2
是一个 ZeroMQ
服务器,它是一个黑匣子,
和
App1
是一个 ZeroMQ
客户端,但它实际上是一个前端服务器.前端服务器将处理来自客户端的一些请求,然后与 App2 服务器进行通信.
whereApp2
is a ZeroMQ
server and it's a black box,
and
App1
is a ZeroMQ
client, but it is in fact a frontend server. The frontend server will process some requests from the clients and then will communicate with the App2 server.
鉴于:
- 在任何时候,任何服务器"都可能关闭或重新启动.
- 我想启动任何应用,即使其他应用没有运行.
- 如果 App1 在 App2 关闭时启动,我想知道 App2 何时启动.
- At any point in time any of the "servers" can go down or be restarted.
- I want to start any of the apps, even if the other app is not running.
- If App1 is started when App2 is down, I want to know when App2 is up.
是否可以仅使用 ZeroMQ
内置函数 来实现 3.,或者我是否需要使用不同的机制来通知 App1 App2 上线?
推荐答案
Item 3
: using pure ZeroMQ
built-ins
Fig.1:
为什么使用简单的REQ/REP
Item 3
: using pure ZeroMQ
built-ins
Fig.1:
Why it is wrong to use a naive REQ/REP
XTRN_RISK_OF_FSA_DEADLOCKED ~ { NETWORK_LoS
: || NETWORK_LoM
: || SIG_KILL( App2 )
: || ...
: }
:
[App1] ![ZeroMQ] : [ZeroMQ] ![App2]
code-control! code-control : [code-control ! code-control
+===========!=======================+ : +=====================!===========+
| ! ZMQ | : | ZMQ ! |
| ! REQ-FSA | : | REP-FSA! |
| !+------+BUF> .connect()| v |.bind() +BUF>------+! |
| !|W2S |___|>tcp:>---------[*]-----(tcp:)--|___|W2R |! |
| .send()>-o--->|___| | | |___|-o---->.recv() |
| ___/ !| ^ | |___| | | |___| ^ | |! \___ |
| REQ !| | v |___| | | |___| | v |! REP |
| \___.recv()<----o-|___| | | |___|<---o-<.send()___/ |
| !| W2R|___| | | |___| W2S|! |
| !+------<BUF+ | | <BUF+------+! |
| ! | | ! |
| ! ZMQ | | ZMQ ! |
| ! REQ-FSA | | REP-FSA ! |
~~~~~~~~~~~~~ DEADLOCKED in W2R ~~~~~~~~ * ~~~~~~ DEADLOCKED in W2R ~~~~~~~~~~~~~
| ! /\/\/\/\/\/\/\/\/\/\/\| |/\/\/\/\/\/\/\/\/\/\/! |
| ! \/\/\/\/\/\/\/\/\/\/\/| |\/\/\/\/\/\/\/\/\/\/\! |
+===========!=======================+ +=====================!===========+
<小时>
Fig.2:
如何实现需求Item 3
,使用纯ZeroMQ代码> 内置函数.
App1.PULL.recv( ZMQ.NOBLOCK )
和 App1.PULL.poll( 0 )
很明显
App1.PULL.recv( ZMQ.NOBLOCK )
and App1.PULL.poll( 0 )
are obvious
[App1] ![ZeroMQ]
code-control! code-control
+===========!=======================+
| ! |
| !+----------+ |
| .poll()| W2R ___|.bind() |
| ____.recv()<----o-|___|-(tcp:)--------O
| PULL !| |___| | :
| !| |___| | :
| !| |___| | :
| !+------<BUF+ | :
| ! | : ![App2]
| ! | : [ZeroMQ] ! code-control
| ! | : [code-control ! once gets started ...
| ! | : +=====================!===========+
| ! | : | ! |
| ! | : | +----------+! |
| ! | : | |___ |! |
| ! | : | |___| <--o-<.send()____ |
| ! | :<<-------<tcp:<|___| W2S|! PUSH |
| ! | : .connect() <BUF+------+! |
| ! | : | ! |
| ! | : | ! |
+===========!=======================+ : +=====================!===========+
这篇关于“服务器"到“服务器"零MQ通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!