javascript - 有没有办法将来自 NodeJS Azure Function 的消息延迟放入 Azure 存储队列中?

标签 javascript azure azure-storage-queues

我正在编写一个带有队列触发器的 JavaScript Azure 函数。当我从队列中收到消息时,如果我准备好处理它,我就会这样做。如果不是,我想将消息延迟 15 分钟放回队列,这样至少 15 分钟内我不会再次处理它。

我找到了几个如何使用 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

但我还没弄清楚如何在 Javascript 中做类似的事情。

我浏览了Azure Storage Queue SDK for NodeJS并尝试了以下代码,期望该消息在 60 秒内不可见:

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})
};

但是,消息仍然立即入队/出队。

如何将消息排入队列,使其在 15 分钟内不会被处理?

最佳答案

我认为以下代码行存在大小写问题:

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

visibilitytimeout 应为 visibilityTimeout

您可以尝试使用以下代码吗:

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

请参阅MessagesEnqueueOptionalParams了解更多详细信息:https://github.com/Azure/azure-sdk-for-js/blob/ee728d567b6a2aa73c83fcd68fc1557a6fb3072c/sdk/storage/storage-queue/src/generated/src/models/index.ts .

关于javascript - 有没有办法将来自 NodeJS Azure Function 的消息延迟放入 Azure 存储队列中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58619056/

相关文章:

javascript - "message"使用 postMessage 时未触发事件

javascript - close 似乎不适用于 WebSocket

javascript - 基准 Javascript : onclick in tag vs click in js

azure - 无法在 VS Code 上登录 Azure 帐户

Azure QueueClient 与 CloudQueue

javascript - 使用 jquery 将 Html 转换为搜索文本

azure - 我应该将 AzureWebApp 任务指向什么路径?

azure - 如何在 Jenkins Docker 容器中挂载 Azure 应用服务存储?

c# - 对于 T4 模板的 Azure 队列构建来说,这是一个好的/优选的模式吗?

azure - 重置 Azure 存储队列消息的可见性