Search code examples
azureservicebus

Status change of Azure Service Bus


I have created a SB in the azure portal. By default the status is showing as Active. Let me have a scenario where i want to change the status of this SB, any idea on how to do that? Any pointers will be very helpful. We have 2 service bus and one needs to be active at a time. So how can we manage that?


Solution

  • By default the status is showing as Active. Let me have a scenario where i want to change the status of this SB, any idea on how to do that?

    Service Bus works as a container or a namespace. The status of Azure Service Bus is internal used, we can't change it on Azure portal or using any API.

    As @Sean Feldman said, we can only enable or disable the entities(queues or topics) in the Service Bus in the properties panel.

    enter image description here

    To disable all the queues and topics in a Service Bus, you could using following code.

    string connectionString = "your connection string of service bus";
    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
    
    IEnumerable<QueueDescription> queueList = namespaceManager.GetQueues();
    
    foreach (QueueDescription qd in queueList)
    {
        qd.Status = EntityStatus.Disabled;
        namespaceManager.UpdateQueue(qd);
    }
    
    IEnumerable<TopicDescription> topicList = namespaceManager.GetTopics();
    
    foreach (TopicDescription td in topicList)
    {
        td.Status = EntityStatus.Disabled;
        namespaceManager.UpdateTopic(td);
    }