What is a good way to connect a synchronous http request / response model with a queue based asynchronous model?
When a custom HTTP request arrives, it generates a job request that goes into the queue ( beanstalkd in this case). One of the workers picks up the request, does the work and prepares the answer.
The queue model is not a request / response β there are only requests, not answers. So the question is, what is the best way to get the answer back to the HTTP world and back to the user?
Ideas:
Beanstalkd supports light threads or queues (they call them pipes). We could create a handset for each request, so that the worker creates a message on that handset, and the http process sits and waits for a response to the handset. I don't particularly like this one, as it has apache processes sitting around memory.
Survey the http client for a response. A custom HTTP request starts the job in the queue and returns immediately. The client (userβs browser) periodically checks the response. On the backend, the worker places his answer in memcached, and we connect nginx to memcached so that the survey is easy.
Use Comet . Like the second option, but with a more attractive http message to avoid polling.
I am inclined to 2 because it is easily and well known (I have not used a comet yet). I guess there is probably also a much more obvious model that I did not think about. What do you think?
Parand
source share