Sorry to reply to this late, but did you resolve your issue? I noticed in your code snippet, you are using two different instances of ZMQ.Context, one in your Router/Dealer queue, a different one in your Worker. I believe you would need to use the same context in order for inproc to work. That explains why switching to tcp works.
On Sep 23, 2014, at 1:16 PM, Mohit Anchlia <mohitanch...@gmail.com> wrote: > I am trying to use router/dealer with dealer using inproc://, when I run my > program the router seems to bind to the port (netstat), client seem to > connect successfully but the recv after send hangs. Worker on the other hand > doesn't see the request come in from router/dealer. Here is the snippet of my > code, not sure what is wrong here: > > Router/Dealer: > > log.info("Starting ZeroMQ Router on port=" + port); > // Prepare our context and socket > ZMQ.Context context = ZMQ.context(1); > // Socket to talk to clients > ZMQ.Socket clients = context.socket(ZMQ.ROUTER); > clients.bind("tcp://*:" + port); > > // Socket to talk to workers > ZMQ.Socket workers = context.socket(ZMQ.DEALER); > workers.bind("inproc://workers"); > > // Connect work threads to client threads via a queue > ZMQQueue queue = new ZMQQueue(context, clients, workers); > new Thread(queue).start(); > > log.info("Exiting ZeroMQ"); > > Worker: > > public JMSZMQRepServer() { > this.context = ZMQ.context(1); > socket = context.socket(ZMQ.REP); > socket.bind("inproc://workers"); > log.info("Server bind inproc"); > } > > @Override > public void run() { > while (true) { > // Wait for next request from client (C string) > try { > log.info("Start"); > String request = socket.recvStr(0); > // String request = new String(GZIPUtils.gunzip(socket.recv())); > // Do some 'work' > String response = null; > response = doWork(request); > // Send reply back to client (C string) > socket.send(response, 0); > } catch (ZMQException e) { > if (e.getErrorCode() == ZMQ.Error.ETERM.getCode()) { > log.warn("Exiting ", e.getMessage()); > break; > } else { > log.error("Unable to send request", e); > } > } catch (Exception e) { > // TODO Auto-generated catch block > log.error("Error in gunzip", e); > } > } > if (null != socket) { > log.info("Socket closed"); > socket.close(); > } > } > > Client: > > public JMSZMQClient() { > context = ZMQ.context(1); > requester = context.socket(ZMQ.REQ); > requester.connect("inproc://workers"); > log.info("Connected to in proc workers"); > } > public String processRequest(String json) throws DataStoreException { > String result = null; > long latency = System.currentTimeMillis(); > // byte [] bJson = GZIPUtils.gzip(json.getBytes()); > log.info("Send request to zMQ server"); > // requester.send(bJson); > requester.send(json, 0); > result = requester.recvStr(0); > log.info("ZeroMQ client took=" > + (System.currentTimeMillis() - latency)); > MessageUtil.validateZMQMessage(result); > return result; > } > > > > _______________________________________________ > zeromq-dev mailing list > zeromq-dev@lists.zeromq.org > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev