Azure / azure-functions-servicebus-extension

Service Bus extension for Azure Functions
MIT License
65 stars 35 forks source link

ServiceBus Topic/Subscription Triggered Function only works if the Connection String Setting name is set to "AzureWebJobsServiceBus" #179

Closed vijayrkn closed 2 years ago

vijayrkn commented 2 years ago

Creating the bug on behalf of the VS customer: https://developercommunity.visualstudio.com/t/ServiceBus-TopicSubscription-Triggered-/1645874

From the customer:

I have an Azure Function that is triggered by a Service Bus topic/subscription:
public static async Task Run([ServiceBusTrigger("TopicName", "SubscriptionName", Connection = "AzureWebJobsMySBName", IsSessionsEnabled = true)]

This setting AzureWebJobsMySBName exists in the config, and there is a message with a SessionId waiting on the subscription, but the function is not triggering. I have restarted the Function App but it’s still not working. Locally, the function triggers properly.

The only thing that gets this working is when I change the setting name to AzureWebJobsServiceBus (the default setting name). No other setting names that I have tried work. This is not a viable workaround as we may need several functions triggered by connections to different Service Bus Entities.

Thank you for your help in advance.
Ved2806 commented 2 years ago

Thank you for the feedback! We will check for the possibilities internally and update you with the findings.

Ved2806 commented 2 years ago

we are investigating this further and will update you soon with the findings.

Ved2806 commented 2 years ago

Hi @fabiocav could you please look into this?

alrod commented 2 years ago

@Ved2806, I tested with Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.3.0 and it works as expected.

Function1.cs

using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace ServiceBusTest
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run1([ServiceBusTrigger("alrod-topic", "alrod-sub", Connection = "AzureWebJobsMySBName", IsSessionsEnabled = true)]string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
        }
    }
}

local.settings.json

{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet",
      "AzureWebJobsMySBName": "{connection-string}"
    }
}

Note you need to set SessionId on sending a message as IsSessionsEnabled = true. After deploying in Azure you need to create the app setting AzureWebJobsMySBName. local.settings.json is only for local development.