Hi,

You are running into a classic problem and yes, the solution is to use
XREQ/XREP.  However the necessary message format is not documented
yet.  You can look at the code for REQ and see how it constructs the
request, then you can do the same in your client before calling XREQ.

I hope to have this specific use case (how to build reliable
request-reply using XREQ/XREP) documented in the user guide.

It's also possible that we'll be able to build retry/reliability
directly into REQ/REP.

-Pieter

On Tue, Aug 10, 2010 at 10:55 AM, ilejncs <ilej...@narod.ru> wrote:
> Hello!
>
> I need a simple request/response interaction, though I am not happy with 
> ZMQ_REQ/ZMQ_REP pattern.
> The main reason is it is unclear what I supposed to do if a response from a 
> server is delayed or lost.
> Do we have an example covers e.g. reopening the socket in this case?
>
> Is it reasonable to look into XREQ/XREQ direction to have the reliability 
> problem addressed?
>
> Converting the simplest REQ/REP example to XREP/XREP, I've found out it 
> crashes with
> "Assertion failed: msg_->flags & ZMQ_MSG_MORE (xrep.cpp:146)".
> To keep the ball rolling, I've added extra recv (after getsockopt with 
> ZMQ_RCVMORE) and
> extra send with ZMQ_SNDMORE at ZMQ_XREP side, so my server looks like
> ==
>  // Initialise 0MQ context with one I/O thread
>  zmq::context_t ctx (1);
>
>  // Create a ZMQ_REP socket to recieve requests and send replies
>  zmq::socket_t s (ctx, ZMQ_XREP);
>
>  s.bind("tcp://*:23001");
>
>  {
>    zmq::message_t msg_req_head;
>
>    int ret = s.recv(&msg_req_head);
>
>    int64_t more = 0;
>    size_t more_size = sizeof more;
>    s.getsockopt(ZMQ_RCVMORE, &more, &more_size);
>
>
>    std::cout << "received:" <<
>      std::string((const char*)msg_req_head.data(), msg_req_head.size()) <<
>      ", more=" << more <<
>      ", ret=" << ret << std::endl;
>
>    if (more)
>    {
>      zmq::message_t msg_req;
>      int ret = s.recv(&msg_req);
>      std::cout << "received (more):" <<
>      std::string((const char*)msg_req.data(), msg_req.size()) <<
>      ", ret=" << ret << std::endl;
>    }
>
>
>
>    char* response_area = (char*) malloc(100);
>    strcpy(response_area, "this is a response");
>
>    zmq::message_t msg_rep(response_area, strlen(response_area) + 1, my_free);
>
>    s.send(msg_req_head, ZMQ_SNDMORE);
>    std::cout << "sent first part" << std::endl;
>    s.send(msg_rep);
>  }
> ==
> The questions (besides general REQ/REQ reliability advice request) are if it 
> is expected 0mq user have to add extra recv/send
> and if it is correct to return first part of a message to sender.
>
>
> Thanks.
> _______________________________________________
> 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

Reply via email to