ZeroMQ knows which one is coming, the request came from

I'm trying to find out if I have two routines that call the same zeromq socket if it returns from socket.recv () in procedure 1 when it returns. The socket will know to return to procedure 1 (the same as for procedure2, ... routinen).

Therefore ... using a messaging bus with request / response semantics, what is the best template for go in this?

If this helps ... think of the simplest pirate template and implement the RPC style call in this template with zeromq.

Socket; //zeromq socket
//routine 1
socket.send(data) // do i need some identifier here for this routine?
socket.recv() // wait until i get a response from that send
//routine 2 
socket.send(data)
socket.recv()

therefore, in this case, I do not know whether the response will return from procedure 1 or subprogram2. How can I make sure that when I get a response to a socket ... I can report the correct recv () function for routines.

Thank!

+4
source
1

, , zeromq

, - goroutine, , / zmq, .

: ( )

type Req struct {
   Data []byte 
   Reply chan []byte
}

go func() { // probably not the zmq api, but you should get the idea here
    for req := <- requests {
         socket.send(req.Data)
         req.Reply <- socket.recv() 
    }
}
+1

All Articles