azureazure-functionsazureservicebusdlq

Scripts for Dead Letter Queue Notification


I want to get notification when emails moved to Dead Letter Queue from Queue in Azure Service Bus. How to do it with Function App or Shell Script or Power shell?

Example: So lets say right now i have 5 items in dead letter queue, so maybe its something running every hour, if new item is added then it should trigger email notification.?

Thanks in Advance!!

I tried with Power shell and Shell Scripting getting errors


Solution

  • There is a trigger called Service bus trigger in Azure Function which will also work for Dead Lettered messages as below:

    Here you just need to add queuname/$DeadLetterQueue in Service bus trigger:

    using Azure.Messaging.ServiceBus;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.Logging;
    
    namespace FunctionApp204
    {
        public class Function1
        {
            private readonly ILogger<Function1> ri_lg;
            public Function1(ILogger<Function1> logger)
            {
                ri_lg = logger;
            }
            [Function(nameof(Function1))]
            public async Task Run(
                [ServiceBusTrigger("rith/$DeadLetterQueue", Connection = "rith")]
                ServiceBusReceivedMessage message,
                ServiceBusMessageActions messageActions)
            {
                ri_lg.LogInformation("Message ID: {id}", message.MessageId);
                ri_lg.LogInformation("Message Body: {body}", message.Body);
                ri_lg.LogInformation("Message Content-Type: {contentType}", message.ContentType);
                await messageActions.CompleteMessageAsync(message);
            }
        }
    }
    

    After Dead lettered the message:

    enter image description here

    the function gets triggered:

    enter image description here

    To send email you can use SendGrid/ SMTP .