Reputation: 7422
I have a Service Bus queue that I want to consume off of. All of the samples I have found recommend writing something like this:
class Program
{
private static String ServiceBusConnectionString = ConfigurationManager.ConnectionStrings["Microsoft.ServiceBus.ConnectionString"].ConnectionString;
static void Main()
{
var jobHostConfiguration = new JobHostConfiguration
{
ServiceBusConnectionString = ServiceBusConnectionString,
};
var jobHost = new JobHost(jobHostConfiguration);
jobHost.RunAndBlock();
}
}
public class QueueItem
{
public String Name;
public Int64 Id;
}
public class Functions
{
public void ProcessQueueItem([ServiceBusTrigger("queue-name")] QueueItem queueItem)
{
// TODO: process queue item
}
}
The problem with the above code is that the queue name is hard coded in my program. I want to be able to get the queue name from configuration like I do with the queue connection string. Unfortunately, attributes can only be passed compile time constants, so I can't pass in some statically initialized string that comes from configuration.
I looked around a bit and was unable to find any other way to setup Service Bus function binding. Is it just not possible?
Upvotes: 0
Views: 910
Reputation: 28425
You can use a custom INameResolver
to accomplish what you want.
One of the official samples here covers exactly your scenario. Take a look the ShutdownMonitor
function in Functions.cs
and then at the ConfigNameResolver
class.
Upvotes: 1