albin
albin

Reputation: 655

Azure Service Bus Triggered Function - Bind to MessageReceiver

I'm trying to bind to MessageReceiver in an Azure Service Bus Triggered Function.
My goal is to handle dead letter queue messages and complete them.

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run(
                [ServiceBusTrigger(
                        "<topicName>", 
                        "<subscriptionName>/$DeadLetterQueue", 
                        Connection = "connectionstring")] 
                        Message message,
                        ILogger logger,
                        MessageReceiver messageReceiver)
        {
            // TODO: Perform some actions

            await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
        }

The problem is that it fails to bind to the MessageReceiver class.

Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'receiver' to type MessageReceiver. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

Any ideas why the binding fails?

Upvotes: 8

Views: 2258

Answers (1)

albin
albin

Reputation: 655

I figured out what was wrong. I was using 'receiver' as parameter name for MessageReceiver. It turned out that the parameter name has to be 'messageReceiver'. The example I was looking at first used 'receiver', so is this maybe something that has changed?

Upvotes: 12

Related Questions