基于Service Bus触发消息内容的Azure Functions动态输入/输出绑定 [英] Azure Functions dynamic input / output binding based on Service Bus trigger message content
问题描述
我正在尝试创建具有多个绑定的Azure Function 2.0.该功能由 Azure Service Bus Queue 消息触发,我想根据此消息内容阅读 Blob .我已经尝试过以下代码:
I'm trying to create Azure Function 2.0 with multiple bindings. The function gets triggered by Azure Service Bus Queue message and I would like to read Blob based on this message content. I've already tried below code:
public static class Functions
{
[FunctionName(nameof(MyFunctionName))]
public static async Task MyFunctionName(
[ServiceBusTrigger(Consts.QueueName, Connection = Consts.ServiceBusConnection)] string message,
[Blob("container/{message}-xyz.txt", FileAccess.Read, Connection = "StorageConnName")] string blobContent
)
{
// processing the blob content
}
}
但是我遇到以下错误:
Microsoft.Azure.WebJobs.Host:错误索引方法"MyFunctionName".Microsoft.Azure.WebJobs.Host:无法解析绑定参数"message".绑定表达式必须映射到触发器提供的值或触发器绑定到的值的属性,或者必须是系统绑定表达式(例如sys.randguid,sys.utcnow等).
Microsoft.Azure.WebJobs.Host: Error indexing method 'MyFunctionName'. Microsoft.Azure.WebJobs.Host: Unable to resolve binding parameter 'message'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).
我在某处看到可以使用动态绑定,但是也许不可能基于另一个输入绑定来创建输入绑定.有什么想法吗?
I saw somewhere that dynamic bindings can be used but perhaps it's not possible to create input binding based on another input binding. Any ideas?
推荐答案
我实际上感到惊讶,该方法不起作用.有很多带有绑定的怪癖.请试一下:
I'm actually surprise that did not work. There are lots of quirks with bindings. Please give this a shot:
public static class Functions
{
[FunctionName(nameof(MyFunctionName))]
public static async Task MyFunctionName(
[ServiceBusTrigger(Consts.QueueName, Connection = Consts.ServiceBusConnection)] MyConcreteMessage message,
[Blob("container/{message}-xyz.txt", FileAccess.Read, Connection = "StorageConnName")] string blobContent
)
{
// processing the blob content
}
}
创建DTO:
public class MyConcreteMessage
{
public string message {get;set;}
}
确保您在服务总线中使用的消息是这样的:
Ensure that the message that you are using in the servicebus is something like this:
{
"message": "MyAwesomeFile"
}
它现在应该能够读取您的绑定 container/{message} -xyz.txt
并识别该 message
It should now be able to read your binding container/{message}-xyz.txt
and recognize that message
这篇关于基于Service Bus触发消息内容的Azure Functions动态输入/输出绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!