Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 691
albin Avatar asked Jan 16 '20 17:01

albin


People also ask

Where can you define the trigger bindings for an Azure function?

For triggers, the direction is always in. Input and output bindings use in and out. Some bindings support a special direction inout . If you use inout , only the Advanced editor is available via the Integrate tab in the portal.

What is Azure Service Bus trigger?

Azure Functions integrates with Azure Service Bus via triggers and bindings. Integrating with Service Bus allows you to build functions that react to and send queue or topic messages. Action. Type. Run a function when a Service Bus queue or topic message is created.

What is peek lock in Azure Service Bus?

The peek-lock mode tells the broker that the receiving client wants to settle received messages explicitly. The message is made available for the receiver to process, while held under an exclusive lock in the service so that other, competing receivers can't see it.


1 Answers

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?

like image 157
albin Avatar answered Sep 27 '22 19:09

albin