7
votes

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?

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?lokanath das

1 Answers

10
votes

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?