How to check if a Azure Service Bus has Premium Pricing

1.1k views Asked by At

In one of my Azure Web Apps I create an Azure Topic when it doesn't exist yet during the warmup(start) of our Azure Web App.

On topic creation time I want to know whether the service bus has a premium pricing tier, when yes I want to disable express, when no (standard pricing tier) I want to enable express, to prevent exceptions.

Is there a defensive way to check if a premium pricing tier is available on the service bus (for example: using the service bus connection string) ?

When there is no defensive way, I can always catch the web exception that know raises, but I want to prevent the exception if I can.

Edit: After consulting our lead-dev we decided to skip the EnableExpress setting completely in our DTAP. So I don't need to implement the SKU check at all. Be aware to not set the EnableExpress property at all otherwise you get the webexception in Premium SKU.

3

There are 3 answers

2
Gaurav Mantri On

Is there a defensive way to check if a premium pricing tier is available on the service bus (for example: using the service bus connection string)?

Unfortunately there's none as of today. Service Bus Client SDK does not expose this information. This feature has been asked from the Service Bus team and there's an open issue on Github for that: https://github.com/Azure/azure-service-bus/issues/42.

The differences between Premium and Standard tiers are highlighted here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-premium-messaging. Kind of an anti-pattern but one thing you could do is perform and operation that is only available in Premium tier (say sending a message greater than 256KB in size) and catch the exception (or lack of) to determine if the Service Bus tier is Premium or not.

1
Tom Sun On

If we want to check the Azure Service Bus Pricing tier,we could use the following code with Microsoft.Azure.Management.Fluent SDK.

 var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"c:\tom\azureCredential.txt");
 var azure = Azure
            .Configure()
            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            .Authenticate(credentials)
            .WithDefaultSubscription();

 var serviceBus =  azure.ServiceBusNamespaces.GetByResourceGroup("resourcegroup", "servicebusnamespace");
 var priceTier = serviceBus.Sku.Tier;

enter image description here

Before code we need to create an azure active directory application and assign the correspondent role. We could create the azure credential file following the document. The following is the credential file format.

subscription=########-####-####-####-############
client=########-####-####-####-############
tenant=########-####-####-####-############
key=XXXXXXXXXXXXXXXX
managementURI=https\://management.core.windows.net/
baseURL=https\://management.azure.com/
authURL=https\://login.windows.net/
graphURL=https\://graph.windows.net/
0
0xced On

It's now possible to determine the SKU with the Azure.Messaging.ServiceBus library (which was not available when the question was asked).

using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;

var connectionString = "...";
var client = new ServiceBusAdministrationClient(connectionString);
var properties = await client.GetNamespacePropertiesAsync();
if (properties.Value.MessagingSku == MessagingSku.Premium)
{
    // disable express
}
else
{
    // enable express
}