azure-functionsazureservicebus

Can't get past "Exception binding parameter" when trying to use ServiceBusTrigger


I'm writing my first ServiceBusTriggered Azure function, but am failing to get it to execute successfully.

Connection to the queue is working and the function is attempting to execute when I inject a message (which I'm doing via the Service Bus Explorer in Azure portal). The message is also moved to the dead letter queue after failing for the configured number of retries, as expected.

Here's the code:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace PlayerProcessing.PendingPlayerCustomId;

public class QueueWorker
{
    private readonly ILogger _log;

    public QueueWorker(IServiceProvider serviceProvider)
    {
        _log = serviceProvider.GetService<ILogger<QueueWorker>>();
    }
    
    [FunctionName("ServiceBusQueueTriggerCSharp")]                    
    public void Run(
        [ServiceBusTrigger("pending-player-custom-id", Connection = "AzureServiceBus")] 
        string myQueueItem
    )
    {
        _log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
    }
}

(I initially tried using a JSON object and the application/json content type, but I haven't even been able to get it working with a string and text/plain content type.)

The error I get:

System.Private.CoreLib: Exception while executing function: ServiceBusQueueTriggerCSharp. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'.

Thanks!


Solution

  • I created a sample ServiceBusQueueTrigger function and successfully got the message from Azure Service Bus Queue.

    local.settings.json :

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "<StoragecConneString>",
        "FUNCTIONS_INPROC_NET8_ENABLED": "1",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "AzureServiceBus": "<ServiceBusQueueConnecString>"
      }
    }
    

    Code :

    using System;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Extensions.Logging;
     
    namespace FunctionApp2.PendingPlayerCustomId
    {
        public class QueueWorker
        {
            [FunctionName("ServiceBusQueueTriggerCSharp")]
            public void Run(
                [ServiceBusTrigger("pending-player-custom-id", Connection = "AzureServiceBus")]
                string myQueueItem,
                ILogger log 
            )
            {
                log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
            }
        }
    }
    

    Azure Service Bus Queue :

    I sent a message to the Azure Service Bus Queue as shown below.

    enter image description here

    Output :

    The Service Bus Queue trigger function ran successfully as shown below.

    enter image description here