c# - 如何在 Azure 函数中使用带有主题/订阅的服务总线触发器

标签 c# azureservicebus azure-servicebus-topics azure-functions

我想创建一个 Azure Functions,当新消息添加到主题/订阅时触发。

目前我创建了一个 Azure Function使用 ServiceBusQueueTrigger C# 模板 并将队列名称设置为

topicPath + "/Subscriptions/" + subscriptionName

Azure Functions ServiceBusQueueTrigger C# Template

但是我有这个异常(exception):

Microsoft.ServiceBus: Cannot get entity 'topic-test/Subscriptions/subscription-test' because it is not of type QueueDescription. Check that you are using method(s) with the correct entity type. System.Runtime.Serialization: Error in line 1 position 1762. Expecting element 'QueueDescription' from namespace 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'.. Encountered 'None' with name '', namespace ''. .

Failed to create ServiceBusTrigger with Topic/Subscription in an Azure Function

我以为 Azure 函数使用的是 MessagingFactory.CreateMessageReceiver初始化消息泵但不初始化。

目前是否支持主题/订阅?

最佳答案

是的,支持主题,但不幸的是,我们的 UI 和模板落后于此 - 我们将很快发布一些更新来解决这些问题。

目前,您可以使用高级编辑器直接编辑触发器绑定(bind)。您可以在那里指定您的 subscriptionNametopicName 值。这是一个例子:

{
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "name": "message",
      "direction": "in",
      "subscriptionName": "subscription-test",
      "topicName": "topic-test",
    }
  ]
}

一般来说,由于 Azure Functions 构建在 WebJobs SDK 之上,我们的各种绑定(bind)直接映射到对应的 SDK。例如 serviceBusTrigger 映射到 ServiceBusTriggerAttribute它具有 SubscriptionName/TopicName 属性。因此,期望在函数元数据模型中看到相同的属性。

关于c# - 如何在 Azure 函数中使用带有主题/订阅的服务总线触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36707496/

相关文章:

c# - 放大图片框时图像变得模糊

c# - 在 C# 中使用类型不匹配异常

c# - Azure 函数 V2 中的延迟消息 : The lock supplied is invalid

azure - 为 SignalR ASP.NET 项目选择正确的项目类型和 Windows Azure 服务

Azure 服务总线主题和多实例订阅者

c# - 使用 Redemption 将 MSG 转换为 EML 后,内部地址丢失

c# - Azure 服务总线触发器不同时处理基于 session 的队列

azure - New-AzServiceBusRule cmdlet 随机失败并出现 "already exists"错误

azure - 我们如何为服务提供对 Azure 服务总线上多个主题(但不是全部)的监听访问

c# - 访问同一个类中的公共(public)方法需要一个实例?