[nanomsg] Re: Asynchronous REPREQ

  • From: Andrew Starks <andrew.starks@xxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Tue, 4 Feb 2014 19:16:26 -0600

On Tuesday, February 4, 2014, Bradley Volen <bradvolen@xxxxxxxxx> wrote:

> Hello,
>
> I have looked through the archives and have seen this come up multiple
> times, but I haven't seen any concrete answer to this. How can I have a
> single worker thread process multiple requests (from the same or different
> clients) simultaneously.
>
> Say I get a request that I can't fulfill until data becomes available a
> few seconds later. I'd like the worker to be able to hold onto the request
> and process others in the meantime. The worker then might get triggered via
> another socket (maybe a bus type broadcast to all workers) that new data is
> available and then the outstanding request can maybe be fulfilled.
>
> I currently have a service that is using an Asynchronous (node like)
> webserver to accomplish this, but its using http simply to take advantage
> of the node-like webserver. If I could use nanomsg sockets and take
> advantage of tcp/unix/inproc and the more interesting control paradigms
> provided by nanomsg, that would be great.
>
> Thanks!
>

I'm using repreq and I think that this won't work. As soon as you try to
receive the second time, I believe that you'll receive "bad state" or
similar.

Consider spooling another thread, instead? In exchange for not working in
the way that you are asking about, you can spoil up N service threads with
the same rep address. So long as each is capable of responding in the same
way you're good and your service is far less complex.

An alternative is to create a device in the middle, in order to
queue pending/blocked responses. At that point, you may decide that repreq
is not exactly what you want.

Other related posts: