0

How to read the message from the service bus dead-letter queue? I'm able to read message-id and a sequence number of the message, but I need the actual message. Can someone help me with this? Is it possible to read the actual message?

jaas
  • 131
  • 1
  • 5
  • whats the error you are getting? where's the code? – 4c74356b41 Apr 07 '20 at 05:40
  • Hi @Jaas, Yes, it is possible to read the message-id, sequence number and the actual message payload fro the dead-letter queue. If you are looking to do the functionality straight away, you shall do it through Serverless360. – Nadeem Duke Apr 11 '20 at 13:21

1 Answers1

0

Before reading message form deadletter queue, you should check what was the reason of fail? If some service was not available then Create WebJob and try below code and process messages.

public void GetDeadLetterMessagesAsync(string connectionString, string queueName)
    {
        var queueClient = QueueClient.CreateFromConnectionString(connectionString, QueueClient.FormatDeadLetterPath(queueName));
        while (true)
        {
            BrokeredMessage bmessgage = queueClient.Receive();
            if (bmessgage != null)
            {
                string msg = new StreamReader(bmessgage.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();
                //Custom business logic to prcess your message
                bmessgage.Complete();
            }
            else
            {
                break;
            }
        }
    }

If message having an issue then you should read and display message on UI so back office team can correct message otherwise it will fail again.

Pankaj Rawat
  • 4,037
  • 6
  • 41
  • 73