Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting http request/response model with asynchronous queue

What's a good way to connect the synchronous http request/response model with an asynchronous queue based model?

When the user's HTTP request comes it generates a work request that goes onto a queue (beanstalkd in this case). One of the workers picks up the request, does the work, and prepares a response.

The queue model is not request/response - there are only requests, not responses. So the question is, how best do we get the response back into the world of HTTP and back to the user?

Ideas:

  1. Beanstalkd supports light weight topics or queues (they call them tubes). We could create a tube for each request, have the worker create a message on that tube, and have the http process sit and wait on the tube for the response. Don't particularly like this one since it has apache processes sitting around taking memory.

  2. Have the http client poll for the response. The user's initial HTTP request kicks off the job on the queue and returns immediately. The client (the user's browser) polls periodically for a response. On the backend the worker puts its response into memcached, and we connect nginx to memcached so the polling is light weight.

  3. Use Comet. Similar to the second option, but with fancier http communication to avoid polling.

I'm leaning towards 2 since it's easy and well know (I haven't used comet yet). I'm guessing there's probably also a much better obvious model I haven't thought of. What do you think?

like image 765
Parand Avatar asked Jan 14 '09 19:01

Parand


People also ask

Why is the queue service asynchronous?

The Queue Service will be asynchronous to avoid thread starvation when there are many http requests in flight. 1. Consumer sends a request to the Queue Service via POST 2. Queue Service receives the request 3. Queue Service sends a request to the Worker via POST (immediately or delayed depending on the state of the queue) 4.

How do I use asynchronous request-response in async request?

Using HTTP asynchronous request-response. When the SOAPAsyncRequest property Use HTTP asynchronous request-response is selected, the SOAPAsyncRequest node passes the HTTP socket to the paired SOAPAsyncResponse node to allow the backend server to reply using the same socket.

How does the httpasyncrequest node work?

The HTTPAsyncRequest node always uses asynchronous HTTP socket handling to make asynchronous requests and responses. The asynchronous request nodes return control to the flow without waiting for a response.

How do I get a response from a soap async request?

You can make HTTP requests and receive a response asynchronously using the HTTPAsyncRequest and HTTPAsyncResponse nodes, or the SOAPAsyncRequest and SOAPAsyncResponse nodes, in your message flow. Using WS-Addressing to direct the response to the paired SOAPAsyncResponse node.


1 Answers

Here's how to implement request-response efficiently on JMS which might be helpful (though Java/JMS centric). The general idea is to create a temporary queue per client/thread then use correlationIDs to correlate requests to replies etc.

like image 58
James Strachan Avatar answered Oct 30 '22 12:10

James Strachan