Search code examples
.netazureasp.net-coreazureservicebusazure-servicebus-queues

How to get current Azure Service Bus Namespace Connection String via code


Is there a way to get the connection string of an Azure Service Bus Namespace by just supplying the namespace name?

I currently have the connection string hard-coded in the config but this will change after deployment to the next environment. I know what the namespace will be but wont have access to the portal to retrieve its connection string.

Anyone know if this is possible or if there is a better approach for this scenario?


Solution

  • It's not possible to derive Azure Service Bus namespace connection string from the namespace name solely. It would be completely insecure and anyone would be able to gain access to any namespace. There are common practices about secrets management. I'll list a few of those and you'll have to research and see what works for your scenario.

    • Environment variable - the value can change per environment, but the code is using the same environment variable to read the connection string in different environments.
    • Secret manager
    • Azure App Configuration Service - in preview, but stable and works great