在 Azure 存储队列触发器中引发错误

问题描述 投票:0回答:1

我正在我的天蓝色存储队列触发器中调用外部API,该触发器本身是由另一个端点启动的。调用外部 API 可能会失败,因此我想抛出一个错误,以便应用我的

host.json
参数:

  "extensions": {
    "queues": {
      "maxPollingInterval": "00:00:01",
      "visibilityTimeout": "00:00:30",
      "batchSize": 16,
      "maxDequeueCount": 5,
      "newBatchThreshold": 8,
      "messageEncoding": "base64"
    }
  }

简化代码:

export async function cashbackStorageQueueTrigger(
    queueItem: unknown,
    context: InvocationContext
): Promise<void> {
    try {
        const {
            // ...props
        } = queueItem;
        // Requesting the cashback
    } catch (error) {
        context.error("Error processing cashback request: ", error);
        throw new Error(`Error processing cashback request: ${error}`);
    }
}

上面的代码并没有再次触发storageQueueTrigger。即使 API 调用失败,调用详细信息也会显示“成功”。我是不是做错了什么?

node.js typescript azure azure-functions azure-storage-queues
1个回答
0
投票

上面的代码并没有再次触发storageQueueTrigger。即使 API 调用失败,调用详细信息仍显示“成功”

请确保您使用的队列名称和连接字符串是否正确。

  • 我有下面的存储队列触发器V4功能,当向存储队列发送消息时它按预期工作。
import { app, InvocationContext } from "@azure/functions";

export async function storageQueueTrigger1(queueItem: unknown, context: InvocationContext): Promise<void> {
    context.log('Storage queue function processed work item:', queueItem);
}

app.storageQueue('storageQueueTrigger1', {
    queueName: 'myqueue',
    connection: 'afrinstore01_STORAGE',
    handler: storageQueueTrigger1
});
  • 我已在本地设置文件中添加了连接字符串。
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "afrinstore01_STORAGE": "DefaultEndpointsProtocol=https;AccountName=<storageAccountName>;AccountKey=cRW************StUaB2QA==;EndpointSuffix=core.windows.net"
  }
}
  • 然后我通过单击
    fn + f5 Azure: Start
    启动了 Azurite。
  • 通过这样做,我能够得到预期的回应。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.