Martin, thanks for the detailed explanation. Now, it's clear to me.
I see the light ;-) you are queuing the PAYLOAD, not the POST request, the request object and transfer that it was born with the post.
Now I understand the situation (I hope ;-) I see three main use cases:
a- you need to queue the payload, process it, without sending a response to the client.
b- you need to queue the payload, process it, and the client needs a response in the associated (to original request) response.
c- you need to queue the payload, process it, and the client needs a result, in the future.
Case a: can be solved easily, only en-queue the data/message, and process it in a consumer process.
Case c: it's like case a, and, as you say, a client could poll the result. I used this case in a game demo past year: the user started a new game, send the request to main web site (not node yet), the web site send the payload to an Azure queue, Azure workers process the command, making the provisioning of the new game (board, initial position, maybe notify to other players), and the client (browser) polls a blob storage that has the game board/room status (ready, in progress.. etc).
Case b: hmmm.. I could make a callback function:
var newfn = function(result) {
///....
res.write(result); // res is a free "outer" variable, in this closure
res.end();
}
save it in an object as
var nc = ncallbacks++;
callbacks[nc] = newfn;
and put the nc value in the message to put into the queue. Many consumers can process that messages, and then, sent a result to a second queue, with the nc value in the result. The original web site consumes that queue, and then, something like:
result = message.result;
cb = callbacks[nc];
delete callback[nc];
cb(result);
If you have many web apps, there is a result queue by each one. The message sent to the first queue, should have not only nc, but the name of the queue associated to the inicial web app.
Maybe, instead of a result queue, a pub/sub-like solution could be used.
But I guess case b is the difficult one.
Another alternative: instead of queue, use an RPC solution, like dnode. And the web app connects and balance the loads to many RPC servers.
I used the callback "old trick" in