none
Output binding not working...? RRS feed

  • Question

  • Hi,

    I'm trying to use JavaScript to write an Azure Function that outputs to a storage queue...but it's not working. Can someone please take a look and let me know what I'm doing wrong. I'm using a Manually-triggered function to debug this.

    Bindings:

    {
      "bindings": [
          {
          "type": "queue",
          "name": "outputQueueItem",
          "queueName": "readytoprocess",
          "connection": "mystorageresource_STORAGE",
          "direction": "out"
        },
        {
          "type": "manualTrigger",
          "direction": "in",
          "name": "input"
        }
      ],
      "disabled": false
    }

    Code:

    module.exports = function (context, input, outputQueueItem) {
        context.log('Node.js manually triggered function called');
        context.log(arguments);
        context.done(null, "New queue item: " + context.bindings.input);
    };

    The log shows this:

    2016-08-30T10:01:34.307 Function started (Id=d58cdb15-5aa3-4a9f-8ac0-cb867f732ec6)
    2016-08-30T10:01:34.307 Node.js manually triggered function called
    2016-08-30T10:01:34.323 { '0': 
       { invocationId: 'd58cdb15-5aa3-4a9f-8ac0-cb867f732ec6',
         log: [Function],
         bindings: { input: 'test123' },
         bind: [Function],
         bindingData: 
          { input: 'test123',
            InvocationId: 'd58cdb15-5aa3-4a9f-8ac0-cb867f732ec6' },
         done: [Function] },
      '1': 'test123' }
    2016-08-30T10:01:34.323 Function completed (Success, Id=d58cdb15-5aa3-4a9f-8ac0-cb867f732ec6)

    The bindings object in the log only contain the input bindings...not the output ones. Why?

    Calling context.done(null, "yadda yadda"); does NOT put anything in my storage queue...should it?

    Thanks for any insight you can give.


    Tuesday, August 30, 2016 10:03 AM

Answers

  • You can set the value for the output binding in a couple ways. First, by passing an object with keys mapping to your output binding names like so:

    module.exports = function (context, input) {
        context.log('Node.js manually triggered function called with input:', input);
        context.done(null, {
            outputQueueItem: input
        });
    };

    Or by setting on the bindings object, like below:

    module.exports = function (context, input) {
        context.log('Node.js manually triggered function called with input:', input);
        context.bindings.outputQueueItem = input;
        context.done();
    };

    For more details, the above is covered in our Node.js documentation online here.


    Mathew Charles [MSFT]






    Wednesday, August 31, 2016 1:00 AM

All replies

  • Update: I created a fresh C# manual-trigger function, with the same output binding to the storage queue.

    It works fine, and works every time.

    I cannot get the Node.js version of it, with the exact same output binding config, to work at all. I've tried lots of different things, but cannot work out how to write out to a storage queue from a Node.js Azure Function.

    Has anyone done this?

    Tuesday, August 30, 2016 5:51 PM
  • Update: Still cannot get it to work. Tried a squillion things. Simply CANNOT get Node.js functions to output to a storage queue through output bindings.

    My solution: use the Node.js Azure-storage module (azure-storage), like this:

    const azure = require('azure-storage');
    ...
    const queueSvc = azure.createQueueService(storageName, storageKey);
    
    queueSvc.createMessage(queueName, base64MessageText, function (error, result, response) {...});


    At first it didn't work, but then I discovered that you need to Base64 encode the message string.

    I'm disappointed that I couldn't get the proper solution to work, but at least there's a workaround. I wonder if the Node.js Azure-Functions stuff is fully implemented yet. Maybe not.
    • Edited by ADaborn Tuesday, August 30, 2016 10:49 PM
    Tuesday, August 30, 2016 10:47 PM
  • You can set the value for the output binding in a couple ways. First, by passing an object with keys mapping to your output binding names like so:

    module.exports = function (context, input) {
        context.log('Node.js manually triggered function called with input:', input);
        context.done(null, {
            outputQueueItem: input
        });
    };

    Or by setting on the bindings object, like below:

    module.exports = function (context, input) {
        context.log('Node.js manually triggered function called with input:', input);
        context.bindings.outputQueueItem = input;
        context.done();
    };

    For more details, the above is covered in our Node.js documentation online here.


    Mathew Charles [MSFT]






    Wednesday, August 31, 2016 1:00 AM
  • Thanks - I tried both methods and they work well :)

    Awesome. It runs a lot faster than using the azure-storage module too, which is a bonus.

    Thanks for your help.

    Wednesday, August 31, 2016 2:37 PM