azureservicebus

Local Azure Function Service Bus Trigger doesnt pick up messages but no information


I have a very frustrating issue

 [FunctionName("MyFunction")]
 public async Task MyFunctionAsync(
 [ServiceBusTrigger("%AzureTopicName%", "mysubscription", Connection = "event-bus-connection")] Message message)
 { 
    //My logic here
 }

This never gets hit

I have checked and verified all configuration and there are no issues

Messages are being written to the service bus which would not happen if there was a config issue

However, my trigger never gets fired even though messages are in the subscription

Has anyone ever seen this?

This is local execution not Azure

Paul


Solution

    1. Validate the connection string, Subscription, Topic names used in the function code are correct. Get Connection string from Service Bus Namespace to use in function code.

    enter image description here

    1. Check if the messages are moving to the dead-letter queue or the messages being processed by another function.

    I have followed below steps and able to trigger the Service Bus Topic Triggered Azure function.

    enter image description here

    Code Snippet:

    [FunctionName("Function1")]
    public void Run([ServiceBusTrigger("mytopic", "mysubscription", Connection = "demo")]string mySbMsg, ILogger log)
    {
        log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
    }
    

    local.settings.json:

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "demo": "Endpoint=sb://<ServiceBus_name>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=GRWoe2XXXXXXXXXXXXXXbEd8Ing="
      }
    }
    

    enter image description here

    Console Output:

    Functions:
    
            Function1: serviceBusTrigger
    
    For detailed output, run func with --verbose flag.
    [2024-03-31T10:41:54.990Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
    [2024-03-31T10:42:15.389Z] Executing 'Function1' (Reason='(null)', Id=b57524a6-4fb8-4586-9bfb-c88e23d137bb)
    [2024-03-31T10:42:15.394Z] Trigger Details: MessageId: 129a51488e34478db8ff88c43308da8b, SequenceNumber: 1, DeliveryCount: 1, EnqueuedTimeUtc: 2024-03-31T10:42:12.1620000+00:00, LockedUntilUtc: 2024-03-31T10:43:12.2400000+00:00, SessionId: (null)
    [2024-03-31T10:42:15.433Z] C# ServiceBus topic trigger function processed message: Hello
    [2024-03-31T10:42:15.490Z] Executed 'Function1' (Succeeded, Id=b57524a6-4fb8-4586-9bfb-c88e23d137bb, Duration=205ms)