Getting Azure Service Bus Namespace Information

Introduction

Starting from version 3.3 of the .NET Standard client library for Azure Microsft Bus service, we can get programmatically its namespace information. In this blog post, I explain how to create a new vanilla Service Bus and how to get its namespace info using C#.

Prerequisites

I used the following tools and libraries:

Azure Service Bus

One among my favorite Azure services is the Azure Service Bus. That's why I prefer to save it in my saved list. It's a shortcut for me to create a new Service Bus.

Azure Service Bus is a cloud-based messaging service providing queues and topics with publish/subscribe semantics and rich features. This fully managed service is available in multi or single tenant configurations with no servers to manage or licenses to buy.

We use Service Bus to :

  • Build reliable and elastic cloud apps with messaging.
  • Protect our application from temporary peaks.
  • Distribute messages to multiple independent backend systems.
  • Decouple our applications from each other.
  • Ordered messaging scaled out to multiple readers.

Namespace Creation

It is straightforward to create a new Service Bus. First, we create a namespace by entering its name, pricing tier, subscription, resource group, and location. The choice of the premium tier/SKU is on purpose.

It is highly recommended using premium tier namespaces to get features such as high availability because these features arenโ€™t available in the standard tier.

All customers should use the premium tier for production workloads. The shared environment of the standard tier simply isnโ€™t appropriate for anything but maybe for systems with very low message volumes or systems still in development.

We get the following neat dashboard to have an overview of messages, requests, and performance.

Namespace Info

Before the release of 3.3.0, we used to configure manually the maximum message size. But since 3.3.0, we can use C# to configure it programmatically. In addition, we can know the type of tier/SKU also using C#.

Let's create a new .NET Core Console App using Visual Studio 2019 Preview and name it NamespaceInfoSample. Thanks to NuGet, we can grab easily the .NET Standard package Microsoft.Azure.ServiceBus.

I wrote the following asynchronous method to illustrate the new feature of Azure Service Bus .NET Standard package.

using Microsoft.Azure.ServiceBus.Management;
using System.Threading.Tasks;

namespace NamespaceInfoSample
{
    class Program
    {
        static string ServiceBusConnectionString = "<your_connection_string>";
        static void Main(string[] args)
        {
            MainAsync().GetAwaiter().GetResult();
        }

        static async Task<NamespaceInfo> MainAsync()
        {
            var client = new ManagementClient(ServiceBusConnectionString);
            var taskOfNamespaceInfo = await client.GetNamespaceInfoAsync();
            return taskOfNamespaceInfo;
        }
    }
}

If we break point the return statement and quick watch the taskOfNamespaceInfo variable after running F5, we can get 2 valuable information among others about our Service Bus namespace: MessagingSku and MessagingUnits if the tier/SKU is premium.

Summary

The new added GetNamespaceInfoAsync API of .NET Standard client library for Azure Service Bus provides information related to the namespace including the type of namespace and the tier/SKU (basic/standard/premium), and the number of messaging units allocated for the namespace if its corresponding tier/SKU is premium.

azure Service Bus .NET Standard SKU Visual Studio NuGet

Hi, I'm Maher, Development Technologies MVP. I'm blogging about Microsoft Azure and ASP.NET Core.