2
votes

I'm writing a JavaScript Azure Function with a Queue Trigger. When I get a message from the queue, if I'm ready to process it I do so. If I'm not, I want to put the message back in the queue with a delay of 15 minutes, so that I won't process it again for at least 15 minutes.

I've found a couple of examples of how to do this using a function written in C#

Implementing Delay Queue using one or more standard FIFO Queues

Setting the VisibilityTimeout for a Message added to an Azure Queue via Azure Function Output Binding

But I haven't figured out how to do something similar in Javascript.

I looked through the Azure Storage Queue SDK for NodeJS and tried the below code with the expectation that the message would be invisible for 60 seconds:

const {QueueServiceClient} = require("@azure/storage-queue");

module.exports = async function (context, req) {
    const STORAGE_CONNECTION_STRING = process.env["AzureWebJobsStorage"];
    const queueServiceClient = QueueServiceClient.fromConnectionString(STORAGE_CONNECTION_STRING);
    const queueClient = queueServiceClient.getQueueClient('queue-name');
    const data = 'test message';
    const buff = new Buffer(data);
    const base64data = buff.toString('base64');
    queueClient.sendMessage(base64data, {visibilitytimeout: 60})
};

However, the messages are still enqueued/dequeued immediately.

How can I enqueue a message so it won't be processed for 15 minutes?

1

1 Answers

1
votes

I believe there's a casing issue in the following line of code:

queueClient.sendMessage(base64data, {visibilitytimeout: 60})

visibilitytimeout should be visibilityTimeout.

Can you please try with the following code:

queueClient.sendMessage(base64data, {visibilityTimeout: 60})

Please see MessagesEnqueueOptionalParams for more details here: https://github.com/Azure/azure-sdk-for-js/blob/ee728d567b6a2aa73c83fcd68fc1557a6fb3072c/sdk/storage/storage-queue/src/generated/src/models/index.ts.