【问题标题】:Azure Function Bindings for Service Bus服务总线的 Azure 函数绑定
【发布时间】:2018-08-11 07:48:46
【问题描述】:

我正在关注this documentation 为服务总线队列创建触发器。

我希望能够访问消息属性。我想我可以像这样简单地将Dictionary<string, object> properties 添加到参数列表中:

public static void Run(
        [ServiceBusTrigger(QueueName, Connection = "connectionSetting")]
        // Message message,
        string myQueueItem,
        Int32 deliveryCount,
        DateTime enqueuedTimeUtc,
        string messageId,
        string ContentType,
        Dictionary<string,object> properties,
        TraceWriter log)

但这会引发:

错误索引方法“Program.Run”。 Microsoft.Azure.WebJobs.Host: 无法将参数“属性”绑定到类型 Dictionary`2。确保 绑定支持参数类型。

这里是a list 可能的参数绑定。我哪里错了?

更新:

我尝试将签名更改为

public static void Run(
        [ServiceBusTrigger(QueueName, Connection = "connectionSetting")]
        // Message message,
        string myQueueItem,
        Int32 deliveryCount,
        DateTime enqueuedTimeUtc,
        string messageId,
        string ContentType,
        IDictionary<string, object> properties,
        TraceWriter log)

它会产生同样的错误:

错误索引方法“Program.Run”。 Microsoft.Azure.WebJobs.Host: 无法将参数“属性”绑定到 IDictionary 类型

【问题讨论】:

    标签: azure azure-functions azureservicebus


    【解决方案1】:

    对于函数 v2 运行时,参数名称已更改为 UserProperties

    要修复错误,请将参数更新为以下内容:

    IDictionary<string, object> UserProperties
    

    这是来自服务总线扩展的相关代码。

    https://github.com/Azure/azure-webjobs-sdk/blob/42a711763ddecca9df4caae9c7dc5fe16178880c/src/Microsoft.Azure.WebJobs.ServiceBus/Triggers/ServiceBusTriggerBinding.cs#L127

    【讨论】:

      【解决方案2】:
      IDictionary<string, object> properties
      

      更新:

      对于版本 2,使用以下绑定:

      public static void Run(
              [ServiceBusTrigger(QueueName, Connection = "connectionSetting")]
              Message message,
              string label,
              Int32 deliveryCount,       
              DateTime enqueuedTimeUtc,  
              string messageId,
              string ContentType, 
              ILogger log)
          {           
              log.LogInformation($"C# ServiceBus queue trigger function processed message: {Encoding.UTF8.GetString(message.Body)}");
              var userProperties = message.UserProperties;
          }
      

      【讨论】:

      • 我查看了我的函数 (V1),它适用于所有绑定参数
      • 啊,我的是 V2 - 可能是一个错误?
      • 是的,例如,请参见以下链接:github.com/Azure/Azure-Functions/issues/819
      • 我们如何添加带有MessageSender的UserProperties?
      猜你喜欢
      • 1970-01-01
      • 2020-05-03
      • 2021-11-21
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2020-10-11
      • 2019-10-15
      • 2017-11-30
      相关资源
      最近更新 更多