Azure Service Bus Triggered Function - Bind to MessageReceiver
Asked Answered
P

1

8

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?

Pugilism answered 16/1, 2020 at 17:40 Comment(1)
I fixed the same issue but for some Unit test purpose i have to use IMessageReceiver. but the issue coming up again. Any idea what should be the Variable name?Uzzial
P
12

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?

Pugilism answered 16/1, 2020 at 17:46 Comment(1)
Thank you. I have been banging my head against the desk all morning trying to figure out why this wasn't working. And your post is older than many of the ones I found that say you should use "reciever" as the parameter name.Matsumoto

© 2022 - 2024 — McMap. All rights reserved.