[zeromq-dev] Correct way to use ZeroMQ along with other asynchrnous library

Fengyu Gao feng32tc at gmail.com
Thu Dec 17 06:50:40 CET 2015


Recently, I'm trying to implement a server based on ZeroMQ. The
architecture looks like this:

thousands of zclients (ZeroMQ, Req Mode)  <---------->  one zserver
(ZeroMQ, Router Mode)  <----- libssh-async-api -----> thousands of
servers (sshd)

Basically, the zserver is a ssh command dispatcher. It receives login
/ logout / channel-read / channel-write requests from zclient, and
then talks to libssh API. In this way different zclients (written in
different languages) can connect to a remote server without
implementing the ssh protocol or talking to libssh directly. ZeroMQ
has a lot of language bindings, but libssh does not.

The zclient first sends a packet, telling zserver that it want to
login to remote server. The zserver receives the request, and then
does an asynchronous call to libssh. The call often returns
immediately with something like SSH_AGAIN. The zserver has to poll all
ssh sessions, and send the response back to zclient when the login
operation is done.

The problem is: when I implement the zserver, I have to deal with the
"connection identity" manually. In current stable version of ZeroMQ,
it is a frame of 5 bytes.
I have to map the identity (e.g. 0x006b8b46f0) to an ssh session index
(e.g., ssh-session 0) when a message is received by router. And when
asynchronous libssh call is finally finished, I have to find back the
identity, and prepend it to the original message before sending it to

I think that I'm probably implementing the zserver in the wrong way.
In the demo code of zGuide, users don't have to deal with the
"connection identity", which is fully wrapped under ZeroMQ API.
Is it right? Is there any better way to implement the zclient /
zserver in my scenario?

More information about the zeromq-dev mailing list