Reputation: 35144
Is it possible to define an input binding for my azure function to connect to a Service Bus queue/topic?
I can imagine something similar to this syntax for storage queue but I can't make it work for Service Bus yet, and I don't see examples online.
I'm looking to get hold of an instance of QueueClient
and/or QueueDescription
class.
The use case for the function is to return queue size based on HTTP trigger and name in query parameter.
Upvotes: 1
Views: 1261
Reputation: 13558
No we don't currently support a NamespaceManager
/QueueClient
input binding like we do for Azure Queues. However, you can easily do this yourself using the ServiceBus SDK directly in your function, w/o having to pull in any additional packages. E.g.
#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}");
}
Regarding the doc not being entirely correct for storage queues, I had previously logged an issue here to address that. I've also logged a new issue here for us to expand our ServiceBus binding.
Upvotes: 2
Reputation: 914
Based on this table in the overview section, an input binding for service bus queues/topics is not supported.
Upvotes: 2