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)
Asked
Active
Viewed 608 times
2 Answers
2
I found that it can be done with ServiceBusAdministrationClient.DeleteSubscriptionAsync Method

Sagi Sulimani
- 66
- 7
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
var serviceBusConnectionString = "Endpoint=sb://sample.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=K34CMjptykdwvAT9t7Frz3DX8OlelvSOBWxZfW8oFZwPg=";
var managementClient = new ManagementClient(serviceBusConnectionString);
await managementClient.DeleteSubscriptionAsync("lorem", "ipsum");

Markus Meyer
- 3,327
- 10
- 22
- 35
-
1You 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
-
2Both 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