Search code examples
azurenservicebusazureservicebusazure-configuration

How do I enable the cscfg overrides to work with NServiceBus Azure configuration


When using NServiceBus the Transport connection string doesn't seem to be fetched from the applicable Cloud configuration first but immediately from the app.config.

Options I've tried:

Using the configuration section (:

cscfg

<ConfigurationSettings>
  <Setting name="AzureServiceBusQueueConfig.ConnectionString" value="Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyy" />
</ConfigurationSettings>

app.config

<AzureServiceBusQueueConfig ConnectionString="Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyy" />

Using a custom connection string name:

cscfg

<ConfigurationSettings>
  <Setting name="NServiceBus.Transport" value="Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyy" />
</ConfigurationSettings>

app.config

<connectionStrings>
    <add name="NServiceBus.Transport" connectionString="Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yyy"/>
</connectionStrings>

Also tried to override it by using the following line of code, since this issue is still open (https://github.com/Particular/NServiceBus.AzureServiceBus/issues/20):

configuration.UseTransport<AzureServiceBusTransport>().ConnectionString(CloudConfigurationManager.GetSetting("AzureServiceBusQueueConfig.ConnectionString"));

Or tried to set the connection string name manually, which works again using the app.config but doesn't let the cscfg override.

configuration.UseTransport<AzureServiceBusTransport>().ConnectionStringName("NServiceBus.Transport");

Solution

  • Did you turn the azure configuration source on? You can do so using following extension method on the bus configuration:

    .AzureConfigurationSource()