"Server" - "Server". ZeroMQ Communication

I want to create a system having the following architecture:

+------------------+ +------------------+ | App1. 0mq client | <------> | App2. 0mq server | +------------------+ +------------------+ 

where App2 is the ZeroMQ server, and this is the black box,
and
App1 is a ZeroMQ client, but in fact it is a front-end server. The front-end server will process some requests from clients, and then will communicate with the App2 server.

Given that:

  • At any moment in time, any of the β€œservers” can go down or restart.
  • I want to run any of the applications, even if the other application is not running.
  • If App1 starts when App2 is unavailable, I want to know when App2 gets up.

Is it possible to implement 3. only using the ZeroMQ built-in functions , or do I need to use another mechanism to notify App1 that App2 is in state ?

+3
source share
2 answers

Item 3 : using pure ZeroMQ built-in modules

Fig.1: Why the naive REQ/REP misused

  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: How to implement Item 3 requirement using pure ZeroMQ built-in functions.

App1.PULL.recv( ZMQ.NOBLOCK ) and App1.PULL.poll( 0 ) 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+------+! | | ! | : | ! | | ! | : | ! | +===========!=======================+ : +=====================!===========+ 
+2
source

Although I am not an expert, I once implemented a similar platform.

An additional signaling level ( REQ/REP ) from App2 -> App1 can do this.

Each time App2 appears on the network, msg should be transferred to App1 .

A separate thread in App1 will be able to get this msg from App2 at any time.

+1
source

Source: https://habr.com/ru/post/1260924/


All Articles