Skip to content

app.storageBlob extraOutput w/ queue binding not working #179

Closed
@LuwkasLima

Description

@LuwkasLima

I'm working on a simple blob trigger azure function that writes a message to a queue (output) once a blob is placed in a specified path. When I use the extraOutput with a queue binding, the message isn't recorded.

Investigative information

Note: the queue binding is working as I have another function in the same project that writes to a queue from a http request trigger.

Note 2: [do not know if related] Comparing both functions, if the queue doesn't exist (the name specified for the queue does not matches an existing queue in Azure), the http triggered function will successfully create a queue and record the message, however the blob triggered one will create a queue with a "weird" name and do not record the message.

image

Explanation for the image:

  • First and second queue were created by the blob triggered function
  • Fourth was created by the HTTP trigger function (using the same binding output configuration)

Repro steps

queueBinding.js:

const { output } = require('@azure/functions');

const queueOutput = output.storageQueue({
        // Connections String to the storage account
        connection: 'AzureWebJobsStorage',
        // Name of the queue storage
        queueName: 'newqueue'        
});

module.exports = { queueOutput };

blobToQueue.js:

const {app} = require("@azure/functions")
const {queueOutput} = require("../bindings/queueBinding")

app.storageBlob("blobToQueue", {
    path: "files/{name}",
    connection: "AzureWebJobsStorage",
    authLevel: 'anonymous',
    extraOuptuts: [queueOutput],
    handler: async function (blob, context) {
        try{
            context.log(`Blob ${blob} processed`);
            return context.extraOutputs.set(queueOutput, ['message 1', 'message 2']);
        }catch(error){
            context.log(`Error: ${error}`);
            return error;
        }
    }
})

httpToQueue.js:

const { app, HttpResponse } = require('@azure/functions')
const { queueOutput } = require('../bindings/queueBinding');
const queue = require('../controllers/queue')

app.http('httpToQueue', {
    route: 'httpToQueue', // Route the function will be accessible. Accepts path parameters {parameter}
    methods: ['POST'], // Restricts the function to only be triggered by the specified methods
    authLevel: 'anonymous', // Defines the level of authentication required to access the function
    extraOutputs: [queueOutput], // Defines the extra outputs that will be written to the queue

    // Defines the function that will be executed when the function is triggered
    handler: async function (request, context) {

        // API versioning using query parameters
        try{
            if(!request.query.get('version')){
                context.log(`No version found in request`);
                const response = new HttpResponse({jsonBody: {message: 'Please specify `version` query parameter'}});
                response.headers.set('Content-Type', 'application/json');
                return response;
            }
            /*
            * Here you specify which controller version to use based on the version specified in the request
            */
            if(request.query.get('version') == '0'){
                return queue(request, context);
            }
            else {
                context.log(`Version ${request.query.get('version')} not found`);
                const response = new HttpResponse({jsonBody: {message: 'Please specify a correct `version` query parameter'}});
                response.headers.set('Content-Type', 'application/json');
                return response;
            }
        }catch(error){
            context.log(`Error: ${error}`);
            return error;
        }
    }
});

queue.js:

const { HttpResponse } = require('@azure/functions');
const { queueOutput } = require('../bindings/queueBinding')

async function queue (request, context) {

    try{
    /*
    * If operation is POST, write message to queue storage 
    */
       if(request.method == 'POST'){
            /*
            * Initial checks to confirm that request can be processed.
            */

            // check if request has a body
            if(!request.body){
                context.log(`No body found in request`);
                const response = new HttpResponse({jsonBody: {message: 'No body found'}});
                response.headers.set('Content-Type', 'application/json');
                return response;
            }
            const body = await request.json() || null;
            const { message } = body;

            // Check if the request has a message
            if(!message){
                context.log(`No message found in request body`);
                const response = new HttpResponse ({jsonBody: {message: 'Please specify `message` key inside JSON payload'}});
                return response;
            }

            context.log(`Http function processed request for url "${request.url}" for method "${request.method}"`);
            // Process request by writting the content of the request to a storage queue
            context.extraOutputs.set(queueOutput, message);
            const response = new HttpResponse({jsonBody: {message: `Message registered successfully`}});
            response.headers.set('Content-Type', 'application/json');
            return response;
        }

        
    }catch( error) {
        context.log(`Error: ${error}`);
        return error;
    }


    }

module.exports = queue;

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions