gpt4 book ai didi

azure - 如何使用 azure 函数和服务总线触发器将 blob 存储作为输出绑定(bind)写入

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

我有一个带有服务总线主题触发器的 azure 功能。每次服务总线主题收到消息时,都会触发此函数。

enter image description here我使用以下方法将输出绑定(bind)添加到 Blob 存储:

enter image description here

但是当函数运行时,我在 blob 存储中看不到任何输出。我确信我缺少一些基本代码。

我看到了多个示例,但每个示例都使用 Blob 存储触发器。

最佳答案

我已经在我的环境中重现并得到了预期的结果,并且我遵循了以下过程:

在我的 run.csx 中:

using System;
using System.Threading.Tasks;

public static void Run(string myQueueItem, ILogger log,ICollector<string> outputQueueItem)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
outputQueueItem.Add(myQueueItem);
}

enter image description here

在我的集成中,我添加了如下输出:

enter image description here

在 function.json 中:

{
"bindings": [
{
"name": "myQueueItem",
"connection": "Con",
"queueName": "rithwik",
"direction": "in",
"type": "serviceBusTrigger"
},
{
"name": "outputQueueItem",
"direction": "out",
"type": "queue",
"connection": "AzureWebJobsStorage",
"queueName": "outqueue"
}
]
}

在服务总线队列中发送消息如下:

enter image description here

在我的存储帐户中创建了一个新队列,如下所示,我也收到了消息:

enter image description here

enter image description here

所以你需要添加ouputQueueItem.Add在代码和 ICollector<string> outputQueueItem 内以参数为例。现在你也将得到像我一样的输出。

编辑:

我在代码中添加了几行,请检查:

运行.csx:

using System;
using System.Threading.Tasks;
public static void Run(string myQueueItem, ILogger log,ICollector<string> outputQueueItem,TextWriter outputBlob)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
outputQueueItem.Add(myQueueItem);
outputBlob.WriteLine(myQueueItem);
}

函数.json:

{
"bindings": [
{
"name": "myQueueItem",
"connection": "Con",
"queueName": "rithwik",
"direction": "in",
"type": "serviceBusTrigger"
},
{
"name": "outputQueueItem",
"direction": "out",
"type": "queue",
"connection": "AzureWebJobsStorage",
"queueName": "outqueue"
},
{
"name": "outputBlob",
"direction": "out",
"type": "blob",
"path": "outcontainer/{rand-guid}",
"connection": "AzureWebJobsStorage"
}
]
}

集成中:

enter image description here

容器和 blob 的创建如下:

enter image description here

容器内部:

enter image description here

所以,我做了一些更改,例如 TextWriter作为参数和代码中的 WriteLine 我们可以获得预期的结果,希望这能消除您的疑虑。

关于azure - 如何使用 azure 函数和服务总线触发器将 blob 存储作为输出绑定(bind)写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74195249/

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