And*_*ich 2 c# azureservicebus azure-servicebus-topics azure-functions
使用 azure 函数版本 1,可以接受 BrokeredMessage 消息。
public static void Run([ServiceBusTrigger("MySServiceBus", "MySubscriptionName", AccessRights.Listen, Connection = "MyConnectionString")]BrokeredMessage message, TraceWriter log)
Run Code Online (Sandbox Code Playgroud)
然后使用类似于以下的代码检索属性:
var MyProperty = message.Properties["MyMessageProperty"] as string
Run Code Online (Sandbox Code Playgroud)
使用 2.0 版本的函数 SDK,我无法将传入对象转换为 BrokeredMessage,而不会收到反序列化错误消息
反序列化 Microsoft.ServiceBus.Messaging.BrokeredMessage 类型的对象时出错。输入源的格式不正确。System.Private.DataContractSerialization:输入源的格式不正确。
是否可以使用函数2.0获取消息属性
小智 5
在新世界(Azure Functions .net5)中,您不能再使用代理消息。新的图书馆不满足这一点。
函数应用程序声明不再是[FunctionName=]但[Function=
你不能再接收Message或字节,而只能是字符串。
例子:
[Function("TestFA")]
public async Task Run([ServiceBusTrigger(topicName, subscriberName, Connection = ???)] string messageText, string id, FunctionContext executionContext)
Run Code Online (Sandbox Code Playgroud)
魔法现在在 FunctionContextexecutionContext 中,您可以从中获取属性,例如
KeyValuePair<string, object> props = executionContext.BindingContext.BindingData.Where(x => x.Key == "UserProperties").FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7200 次 |
| 最近记录: |