2

I have some problems in running the azure function (isolated one) based on .net 6. I would like to get the connection string to the service bus from azure app config. All other settings are succesfuly fetched and served with IOptions pattern: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0 With connection string to service bus, I am getting following error when I am trying to run the function locally:

 Microsoft.Azure.WebJobs.Extensions.ServiceBus: Service Bus account connection string 'AzureServiceBus' does not exist. Make sure that it is a defined App Setting.

The functioln looks like this:

using Api.Contracts.BusMessage;

namespace Api.Functions.Queues;

public class Test
{
    private const string FunctionName = "func";

    private readonly ILogger<Test> _logger;

    public Test(ILogger<Test> logger)
    {
        _logger = logger;
    }

    [Function(FunctionName)]
    public async Task Run(
        [ServiceBusTrigger("func", Connection = "AzureServiceBus")]
        BusMessage<string> message)
    {
        _logger.LogInformation("Processing queue trigger message {@Message}", message);
    }
}

Is it even possible to get connection string from Azure App Configuration?

Jacek Majer
  • 345
  • 1
  • 3
  • 14
  • Have you tried looking here?https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=in-process%2Cextensionv5&pivots=programming-language-csharp#connection-string – SlobodanT Oct 10 '22 at 21:44
  • I think if you put in your localsettings.json it will pick it up when run locally. It will pick it up from the Azure App Config when run in Azure. – Scott Mildenberger Oct 10 '22 at 21:44
  • Please refer [this](https://stackoverflow.com/questions/73822115/azure-function-read-appsetting-json/73822752#73822752) thread.Does this help? – RithwikBojja Oct 11 '22 at 00:49
  • Using this article https://dev.to/kenakamu/net-6-service-bus-trigger-azure-function-part-1-50h4] I have managed to use Managed Identity inside Azure, but the connection string, any way, must be placed in "Configuration" tab of function resource. When I am trying to put it as "ServiceBusConnection:fullyQualifiedNamespace" in Azure App Configuration I am getting the same error. – Jacek Majer Oct 13 '22 at 22:11

1 Answers1

1

Service bus connection must come from Function App's own App Settings. It is possible to reference values from Azure App Configuration in the Function App's App settings. See this guide. If you are pulling settings from Azure App Configuration in at runtime of your function, then that will not be usable for the Service Bus connection.

J. Campbell
  • 680
  • 4
  • 5