gpt4 book ai didi

使用无服务器创建的 Azure 队列触发器函数不会触发

转载 作者:行者123 更新时间:2023-12-03 07:08:06 25 4
gpt4 key购买 nike

使用无服务器创建队列触发器函数会创建该函数,但当新消息添加到队列时,它不会触发。当新消息添加到队列时,将触发使用相同配置(队列名称、连接字符串)从门户创建的队列触发函数。

无服务器.yml

...    
functions:
storageQueue:
handler: src/handlers/goodbye.sayGoodbye
events:
- queue: example-queue
name: myQueueItem
connection: STORAGE_CONNECTION_STRING

这是为 serverless 的队列触发功能生成的 json 文件。函数.json

{
"disabled": false,
"bindings": [
{
"type": "queueTrigger",
"direction": "in",
"name": "myQueueItem",
"queueName": "example-queue",
"connection": "STORAGE_CONNECTION_STRING"
}
],
"entryPoint": "sayGoodbye",
"scriptFile": "../src/handlers/goodbye.js"
}

如果该函数是从门户创建的,那么这是为该函数生成的 json 文件。函数.json

{
"bindings": [
{
"name": "myQueueItem",
"queueName": "example-queue",
"connection": "STORAGE_CONNECTION_STRING",
"direction": "in",
"type": "queueTrigger"
}
]
}

正如您所看到的,这两个函数的绑定(bind)部分是相同的,但只有从门户创建的函数才有效。

最佳答案

以下是我在 Visual Studio Code 中创建 JavaScript Stack 的 Azure 无服务器函数 - Azure 队列存储触发器的解决方法,并且在将消息添加到创建的队列后成功触发。

代码是:function.json

{
"bindings": [
{
"name": "myQueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "js-queue-items",
"connection": "storageaccountjbd99_STORAGE"
}
]
}

host.json

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}

local.settings.json

{ 
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Azure Connection Storage string",
"FUNCTIONS_WORKER_RUNTIME": "node",
"storageaccountjbd99_STORAGE": "Azure Connection Storage string"
}
}

enter image description here如果您要连接到 Azure 存储帐户,则此处的 AzureWebJobsStoragestorageaccountjbd99_STORAGE 连接字符串值应该相同。

  • 如果存储帐户是在Azure中创建的,创建函数时会要求选择Azure存储帐户还是使用本地存储帐户,这里我选择现有的Azure存储帐户,因此连接值为存储帐户名称.

  • 之后,我运行该函数,并在 Azure 存储资源管理器中创建名为 js-queue-items 的队列名称,并将消息添加到队列中。

添加消息后,该函数触发其功能并显示输出,如下所示:

enter image description here

关于使用无服务器创建的 Azure 队列触发器函数不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71045198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com