0

Is there any way to delete subscriptions from Azure Service Bus Topic, through C# code? (I know how to delete it only through the Azure portal website)

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35

2 Answers2

2

I found that it can be done with ServiceBusAdministrationClient.DeleteSubscriptionAsync Method

0

This can be done with the ManagementClient.DeleteSubscriptionAsync Method:

Parameters
topicPath: String
The name of the topic relative to the service namespace base address.
subscriptionName: String
The name of the subscription to delete.

Sample:
Topic: lorem
Subscription: ipsum

enter image description here

var serviceBusConnectionString = "Endpoint=sb://sample.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=K34CMjptykdwvAT9t7Frz3DX8OlelvSOBWxZfW8oFZwPg=";
var managementClient = new ManagementClient(serviceBusConnectionString);
await managementClient.DeleteSubscriptionAsync("lorem", "ipsum");

NuGet: Azure Service Bus client library for .NET

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
  • 1
    You were close Markus! Just that you referred me to ManagementClient, instead of ServiceBusAdministrationClient. But you gave me a direction, so thank you! – Sagi Sulimani Aug 07 '22 at 07:56
  • Both options are working. I tested my code on my machine – Markus Meyer Aug 07 '22 at 08:00
  • 2
    Both are correct; ManagementClient belongs to the legacy (deprecated) package. ServiceBusAdministrationClient is the type for the current generation package. – Jesse Squire Aug 07 '22 at 13:19