[zeromq-dev] Client hang on recv

Mohit Anchlia mohitanchlia at gmail.com
Wed Sep 24 20:17:31 CEST 2014


When I change from inproc:// to tcp:// everything seem to work. Not sure
why it's not working, perhaps order in which things are started? I am
starting in this order:

1) Bring up router/dealer -> This also connects router to dealer through
ZMQQueue. Router is tcp and dealer is inproc
2) Bring up workter and connect to inproc

When I change everything to tcp:// it works with exact same code and
sequence of operations

On Tue, Sep 23, 2014 at 11:16 AM, Mohit Anchlia <mohitanchlia at 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.connect("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;
>  }
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140924/2dc5a6e3/attachment.htm>


More information about the zeromq-dev mailing list