Reputation: 171
Here is sample code of the request / response pattern with zeroMQ in python. I would like to know if there is way to process requests from multiple clients concurrently?
import zmq
import time
def main():
context = zmq.Context()
serverSocket = StartServer(context,"9999")
processRequests(serverSocket)
def processRequests (socket):
while True:
print "waiting for request"
msg = socket.recv()
print msg
time.sleep(10)
socket.send("Request processed")
def StartServer(context, port):
socket = context.socket(zmq.REP)
socket.bind("tcp://*:%s" % port)
print "started server on", port
return socket
if __name__ == '__main__':
print "starting IPC server"
main()
Upvotes: 5
Views: 1119
Reputation: 79441
The REQ-REP pattern is a synchronous pattern. If there are two REQ sockets connected to the same REP socket, the REP socket will process requests serially.
If you want to do asynchronous request-reply, you'll want to look into the ROUTER-DEALER pattern, which is the generalized analogue of REQ-REP.
If you want a brokered asynchronous request-reply, look at the "Figure 16 - Extended Request-Reply" section here.
Upvotes: 7