简体   繁体   中英

Azure Function Blob Trigger Retry Count

I have a situation where a blob might fail to process the first time but might work on a subsequent execution.

The issue I am having is around monitoring true failures, at the moment the first failure will throw an exception, which is logged and alerted on but if the first retry completed successfully then there is nothing to do based on the earlier alert.

Is there a way to view the number of retries that have happened, so that I can only alert if it is no longer going to be retried?

You can change your function handler to retrieve the message metadata, including the dequeue count.

Retrieving queue metadata from an Azure Storage Queue Trigger

[FunctionName("QueueTriggerMetadata")]
public static void Run([QueueTrigger("101functionsqueue", Connection = "AzureWebJobsStorage")]CloudQueueMessage myQueueItem, TraceWriter log)
{
    log.Info("101 Azure Function Demo - Retrieving Queue metadata");

    log.Info($"Queue ID: {myQueueItem.Id}");
    log.Info($"Queue Insertion Time: {myQueueItem.InsertionTime}");
    log.Info($"Queue Expiration Time: {myQueueItem.ExpirationTime}");
    log.Info($"Queue Payload: {myQueueItem.AsString}");

    log.Info($"Dequeue Count: {myQueueItem.DequeueCount }");
}

Having said that, you might still want to use the poison queue to handle failed messages like Mike suggests in his answer. It depends on your exact scenario.

After a blob trigger function fails for the last time, Azure should write a message to a storage queue called webjobs-blobtrigger-poison . You can monitor this storage queue for new messages as a way to monitor actual failures after the retries have been exhausted.

See: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp#poison-blobs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM