3

I have this App Service in Azure running as a Web Job. The application is a former Windows Service built using NServiceBus and I have been reconfiguring it to work in Azure.

The application is using AzureServiceBusTransport and I have my Azure Service Bus with a queue set up.

I got it working... when I am using a Shared Access Key configured in my connectionstring like this;

"ConnectionString": "Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=***"

To make it work with Managed Identity I have reconfigured in my NServiceBus EndpointConfiguration with;

transport.CustomTokenCredential(new DefaultAzureCredential());

I also changed my connectionstring to the following;

"ConnectionString": "Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;Authentication=ManagedIdentity"

But when I try to use Managed Identity instead I get the following exception;

ArgumentException: The value 'Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;Authentication=ManagedIdentity' is not a well-formed Service Bus fully qualified namespace.

MYNAMESPACE is obviously correct when I use Shared Access Key but not when I use Managed Identity?

We do have an Azure Function that CAN use Managed Identity and is in that case using;

"ConnectionString": "Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;Authentication=ManagedIdentity"
Per
  • 1,393
  • 16
  • 28
  • It should be possible to achieve using MSI from App Service to Azure Service Bus, like this github.com/Azure-Samples/app-service-msi-servicebus-dotnet. But it seems I can not configure it this way with NServiceBus or I am missing something – Per Nov 05 '21 at 14:28

1 Answers1

3

Just ran into the same issue with NServiceBus. Instead of:

"ConnectionString": "Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;Authentication=ManagedIdentity"

just set:

"ConnectionString": "MYNAMESPACE.servicebus.windows.net"
Thibault
  • 446
  • 7
  • 17
  • Yes, thanks. I did try that as well but receieved another exception and neglected that was a correct exception for me running locally in visual studio. – Per Nov 06 '21 at 08:17
  • For a bit more information on the answer you can refer to this [thread](https://discuss.particular.net/t/nservicebus-in-app-service-using-managed-identity-for-connect-to-azure-service-bus/2815/2?u=tmasternak) on NServiceBus forum – Tomek Masternak Nov 08 '21 at 11:22