Azure函数: Service Bus input binding (not trigger)

标签 azure azureservicebus azure-functions

是否可以为我的 Azure 函数定义输入绑定(bind)以连接到服务总线队列/主题?

我可以想象类似的事情 this syntax for storage queue但我还无法使其适用于服务总线,而且我在网上也没有看到示例。

我正在寻找 QueueClient 和/或 QueueDescription 类的实例。

该函数的用例是根据 HTTP 触发器和查询参数中的名称返回队列大小。

最佳答案

不,我们目前不支持 NamespaceManager/QueueClient 输入绑定(bind),就像我们对 Azure 队列所做的那样。但是,您可以直接在函数中使用 ServiceBus SDK 自行轻松完成此操作,而无需引入任何其他包。例如

#r "Microsoft.ServiceBus"

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;

public static void Run(string input, TraceWriter log)
{
    var connectionString = Environment.GetEnvironmentVariable("<connection>");
    var nsmgr = NamespaceManager.CreateFromConnectionString(connectionString);
    long count = nsmgr.GetQueue("myqueue").MessageCount;
    log.Info($"Message count {count}");
}

关于该文档对于存储队列并不完全正确,我之前记录过一个问题 here解决这个问题。我还记录了一个新问题 here以便我们扩展我们的 ServiceBus 绑定(bind)。

关于Azure函数: Service Bus input binding (not trigger),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435643/

相关文章:

azure - 无法删除 Microsoft Azure 服务总线命名空间

c# - 将 Windows 文件格式转换为 Linux 格式

azure - 如何使用门户中的 Azure 功能将消息发送到 Azure IOT 中心并将其显示在客户端应用程序上

azure - 使用 powershell 设置 Azure 函数 IP 限制

azure - 用于使用新的 VNet 集成功能配置应用服务的 ARM 模板?

python-2.7 - 授权 token 签名有问题

azureservicebus - 为什么 Azure WebJob ServiceBus 默认反序列化 XML?

javascript - Azure Function - 处理消息而不输出结果会发生什么?

unit-testing - 使用 ServiceBusTrigger 对 Azure Function 进行单元和集成测试

azure - 使用了哪个 "diagnostics.wadcfg"?