When I use the following:
var deadLetterPath = SubscriptionClient.FormatDeadLetterPath(topicPath,subName);
var client = SubscriptionClient.CreateFromConnectionString(connectionString, deadLetterPath, subName);
I get an InvalidOperationException
Cannot directly create a client on a sub-queue. Create a client on the main queue and use that to create receivers on the appropriate sub-queue
Some parts of the azure documentation say to use SubscriptionClient.CreateReceiver to access a sub-queue but that method doesn't exist.
If you are using
Microsoft.Azure.ServiceBus
instead ofMicrosoft.ServiceBus
, it is slightly different.As per
EntityNameHelper
class inMicrosoft.Azure.ServiceBus
namespace, for topics, use the subscription path instead of your_queue_name.There is a convention naming for Dead letter queue using Azure Service Bus:
So you can access your dead letter queues the same way you access your queues.
From @SamVanhoutte answer, you can see that the ServiceBus framework provides methods to format the dead letter queue name:
For Service Bus Queue:
QueueClient.FormatDeadLetterPath(queuePath)
For Service Bus Subscription:
SubscriptionClient.FormatDeadLetterPath(topicPath, subscriptionName)
I wrote two small methods to create a message receiver for queue and subscription where you can set if you want the deal letter queue or not:
Does this approach work for you ?
I haven't test it out here (in a meeting), but give it a try
cheers