Search code examples
azureazureservicebusazure-servicebus-queues

How can I pick up deadletters from azure service bus on .netcore 2 application?


I have .net core application which needs to read dead letter queue of Azure ServiceBus. Currently I see Windows.AzureServiceBus for .net full framework, but cannot find similar package for .netcore. Even links to an existing docs will be appreciated.


Solution

  • MessageReceiver is providing that capability: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Core/MessageReceiver.cs

    // in my case ReceiveAndDelete, which will read the queue and delete it as well.
    var receiver = new MessageReceiver(connectionString, $"{QueueName}/$deadletterqueue", ReceiveMode.ReceiveAndDelete);
    
    var latestDeadLetters = await receiver.ReceiveAsync(100);