[zeromq-dev] Client hang on recv

Mohit Anchlia mohitanchlia at gmail.com
Wed Sep 24 21:32:34 CEST 2014


This is my java dependency:

<!-- JeroMQ Pure Java implementation of *libzmq* (
https://github.com/zeromq/jeromq) -->

<dependency>

<groupId>org.zeromq</groupId>

<artifactId>*jeromq*</artifactId>

<version>0.3.4</version>

<!-- More recent <version>0.3.4</version> -->

</dependency>

<!-- Java binding for 0MQ (http://www.zeromq.org) -->

<dependency>

<groupId>org.zeromq</groupId>

<artifactId>*jzmq*</artifactId>

<version>3.1.0</version>

<!-- More recent <version>3.0.1</version> -->

</dependency>

On Wed, Sep 24, 2014 at 12:12 PM, Pieter Hintjens <ph at imatix.com> wrote:

> What version of ZeroMQ are you using?
>
> On Wed, Sep 24, 2014 at 8:17 PM, Mohit Anchlia <mohitanchlia at gmail.com>
> wrote:
> > 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;
> >>  }
> >>
> >>
> >>
> >
> >
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> >
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140924/08847493/attachment.htm>


More information about the zeromq-dev mailing list