0

I am trying to access the queue trigger message as JSON in a JavaScript Azure Functions queue binding as follows, but I get an error that "blobTrigger is not defined" every time a new queue message arrives. I can see the field in the queue message JSON, so is there a way to do this or is this just not possible?

{
  "bindings": [
    {
      "type": "queueTrigger",
      "direction": "in",
      "name": "retryTrigger",
      "queueName": "azure-webjobs-retry"
    },
    {
      "name": "myBlob",
      "type": "blob",
      "direction": "in",
      "path": "{queueTrigger.blobTrigger}"
    }
  ]
}

2 Answers 2

1

I believe you can simplify it from queueTrigger.blobName to just blobName per this doc and callout on using with JS

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#json-payloads

This assumes the queue message is a JSON payload with a property called blobName in my example

Sign up to request clarification or add additional context in comments.

Comments

0

you should use a POCO object in the queue trigger binding, see the following example:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Threading.Tasks;

namespace FunctionApp13
{
    public static class Function9
    {
        [FunctionName("Function9")]
        public static async Task Run(
            [QueueTrigger("azure-webjobs-retry", Connection = "rk2018storagev2_STORAGE")]Payload myQueueItem, 
            [Blob("{ContainerName}/{BlobName}", FileAccess.Read, Connection = "rk2018storagev2_STORAGE")] string myBlobItem, 
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            log.LogInformation($"Blob Content: {myBlobItem}");

            await Task.CompletedTask;
        }
    }

    public class Payload
    {
        public string ContainerName { get; set; }
        public string BlobName { get; set; }

        public override string ToString()
        {
            return $"{ContainerName}/{BlobName}";
        }
    }
}

For portal:

run.csx:

using System;

public static async Task Run(Payload myQueueItem, string myBlobItem, ILogger log)
{
    log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

    log.LogInformation($"Blob Content: {myBlobItem}");

    await Task.CompletedTask;

}

public class Payload
{
    public string ContainerName { get; set; }
    public string BlobName { get; set; }

    public override string ToString()
    {
        return $"{ContainerName}/{BlobName}";
    }
}

function.json:

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "azure-webjobs-retry",
      "connection": "rk2018storagev2_STORAGE"
    },
    {
      "type": "blob",
      "name": "myBlobItem",
      "path": "{ContainerName}/{BlobName}",
      "connection": "rk2018storagev2_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

Test:

{   
   "ContainerName":"test",
   "BlobName":"abc.json"
}

2 Comments

The script is crashing before it gets into my code with the "blobTrigger is not defined" error.
how is look your Payload (POCO) object?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.