As we port more of our node.js code into Azure Functions we see references in the Azure docs that using Storage Queues is the preferred way to delegate processing responsibility instead of using http requests to call other functions.
What is the request/response design pattern we should use for this delegation? Specifically, how can the response sent back through a queue be delivered only to the Function where the request originated?
Here's an example of what we want to do:
- Request comes in to an HTTP Trigger Function A
- Function A places message into Queue X (in JSON format) with the first key being the unique requestId: "ABC345"
- Function A starts listening to Queue Y for the response
- Function B dequeues this message and does its work
- Function B places message with work results added into Queue Y with requestId: "ABC345"
- Function A sees this message with requestId: "ABC345" and returns the HTTP response
How can we get Function A to pick up only the request that it is waiting for?
The getMessage method doesn't seem to be able to selectively listen to a queue, only to grab the top message:
getMessage(queue [, options], callback)
Another angle on this would be if we want multiple Worker Functions to listen to Queue X. Function C would process all requests that have requestType: "query" and Function D would process all requestType: "blob". Without this filtering we would use one queue per Worker function. Is that the right way to do it, too?
Note: We're using node.js but I'm assuming that the Queue API's are equivalent across all SDK's.