1
votes

Can I migrate an Azure Service Bus Queue to a Topic and Subscription by just reconfiguring the path names?

Are there any code changes needed?

Will 3rd parties have to change their code if I keep the names alike?

1

1 Answers

3
votes

No, if you try sending to a topic with the QueueClient you will get an exception:

System.InvalidOperationException: 'Cannot open a Queue client for entity type Topic.'

Likewise trying to receive from the subscription will result in an exception:

Microsoft.Azure.ServiceBus.MessagingEntityNotFoundException: Put token failed. status-code: 404, status-description: The messaging entity 'sb://ns.servicebus.windows.net/subscription' could not be found.

For sending you will need to replace the QueueClient with a TopicClient which has the same constructor.

For receiving you will have to use the SubscriptionClient which needs the Topic as well as the subscription names (so a small change calling the constructor).

QueueClient and TopicClient both inherit from ClientEntity, but ClientEntity does not define any virtual or abstract SendAsync() method, so it is not easy to make anything truly generic.

The code changes required are minimal, in my case I only needed to change the constructors and the declared types for the clients.

So yes, 3rd parties will have to change their code if you decide to migrate...