0

I am trying to enable dead-lettering to storage container when EventGrid fails to publish events to endpoint, but it is not dead-lettering events instead it is dropping the events. Below are the details:

  • Storage Account: abcaccount
  • Container: test
  • Event Subscription: blob-created-event
  • Endpoint Type: Service Bus Topic
  • Service Bus Namespace: xyz-service-bus
  • Topic Name: test-topic
  • Dead Letter Storage Account: abcaccount
  • Dead Letter Container: deadletters

To reproduce the failing scenario, I removed topic (test-topic) from service bus. and uploaded one blob to container (test) which in turn generated event and tried to publish event on service bus topic (test-topic), but after configured retry policy count (10) it dropped event, it should have dead-lettered in container (deadletters) in storage account (abcaccount).

When I enabled diagnostics, I observed NotFound error (the delivery endpoint not found)

Can someone help me please in this regards?

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30

1 Answers1

0

In Azure Event Grid, when events cannot be delivered to the configured endpoint (in your case, the nonexistent Service Bus Topic test-topic), Event Grid should attempt to retry delivery according to the configured retry policy. Once the retry attempts are exhausted, Event Grid would typically drop the event, but it doesn't inherently support dead-lettering events to a Storage container.

  • If your requirement is specifically to capture failed events and store them in a Storage container, you'll need to implement a custom solution that handles the delivery failure and stores events in the Storage container.

Create a function app and replace the below code to capture incoming events and store them in a Storage container.

using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

public static class EventCaptureFunction
{
    [FunctionName("EventCaptureFunction")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        // Read the request body
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();

        // Store the event in a Storage container (replace with your storage logic)
        // You would need to use the Azure Storage SDK to accomplish this.
        // Example:
        // var connectionString = "<YourStorageConnectionString>";
        // var containerName = "deadletters";
        // var blobName = Guid.NewGuid().ToString() + ".json";
        // var blobClient = new BlobClient(connectionString, containerName, blobName);
        // await blobClient.UploadAsync(new MemoryStream(Encoding.UTF8.GetBytes(requestBody)));

        return new OkObjectResult("Event captured and stored.");
    }
}
  • Set-up the endpoint to trigger to the newly created Azure Function's URL enter image description here

  • Trigger events that would normally be sent to your endpoint. Since your configured endpoint is the Azure Function, Event Grid will send events there.

Monitor the Azure Function logs to check that it captures and processes the incoming events.

Suresh Chikkam
  • 623
  • 2
  • 2
  • 6