Martin Peck
Martin Peck

Reputation: 11564

Are Azure Function Bindings Executed in Order?

In a given Azure Function, I can have 1 or more output bindings. For example, I might have a blob storage output (writing a file blob to storage) and a queue output (pushing a message into a queue).

For example, if I have this very simple Azure function (written in Node.js)...

module.exports = function (context, req) {
    context.log('START: Multi-output function.');

    context.bindings.outputBlob = "blob-contents";
    context.bindings.outputQueueItem = "{'message': 'hello!'}";

    context.done();
};

... with the output bindings set up in function.json as follows...

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "blob",
      "name": "outputBlob",
      "path": "outcontainer/{rand-guid}",
      "connection": "AzureWebJobsDashboard",
      "direction": "out"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "outqueue",
      "connection": "AzureWebJobsDashboard",
      "direction": "out"
    }
  ],
  "disabled": false
}

... when do the two output bindings actually fire, and in which order?

For the when part of the question:

  1. Do they fire at the point where the function sets the output binding? (e.g. the line of code that sets context.bindings.outputBlob)
  2. Do they fire at/after context.done()?

For the order part of the question:

  1. Do they fire in the order they're seen in the code?
  2. Do they fire in the order they're seen in function.json ?

Upvotes: 1

Views: 643

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

Output bindings fire after the function execution is completed - after context.done().

The order that you set them in the code has no influence on binding executions.

If you can, treat the actual execution order as the implementation detail and do not rely on it. Having said that, if I'm not mistaken, the actual order will be:

  • Execute all non-queue bindings in order of function.json
  • Then, execute all queue bindings in order of function.json

UPDATE: based on this issue and this issue I conclude that order is not guaranteed at the moment.

Upvotes: 2

Related Questions