skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    @RithwikBojja From Where you have created "ServiceBusTriggered"

    If i create function App choosing powershell Platform i am able to do Service bus trigger in Azure Function.

    If i create it using Powershell Run Time,Am i able to run this script you have shared.

    When i create Function Apps using .Net, i am not able to see "Functions"

    enter image description here

    I create Service bus trigger in Azure Function (Created Using Powershell Run Time).

    Then I use your code, But I am not able to see output as i expected.

    enter image description here

    Please help me to resolve this issue.


  2. 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 .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search