简体   繁体   中英

Azure Storage Blob Trigger is not awakening a sleeping function

This question is similar to Azure Blob Storage trigger Function not firing

However, their problem was that their Azure Function wasn't awaking immediately, giving the impression it wasn't processing triggers from Azure Blob Storage when in fact it was after 10 minutes which is exactly as the MS docs claim.

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

My problem is different. My blob has been sitting in the container now for 9 hours and it still hasn't been processed.

All it does is post a message onto ServiceBus.

[FunctionName("IncomingFileDetected")]
[return: ServiceBus("incoming-file-received", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)]
public static IncomingFile Run(
    [BlobTrigger("incoming-files/{filename}", Connection = "ConnectionStrings:MutableStorage")]
    Stream contents,
    string filename,
    ILogger log)
{
    log.LogInformation($"Detected new blob file: {filename}");
    return new IncomingFile(filename);
}

No messages have appeared in the service bus.

Now, after 9 hours, I have restarted the function app and the blob was processed within about 10 minutes.

Update:

Thanks for Peter Morris's sharing, the problem comes from is service plan is d1. So first make sure you are based on the three kinds of plans: consumption plan, premium plan and app service plan. When we use azure function, even only test, we should use a consumption plan. The smallest in production is S1, which is normally used for testing.

Original Answer:

The below code works fine on my side. Even the consumption plan is no problem.

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp35
{
    public static class Function1
    {
        [FunctionName("Function1")]
        [return: ServiceBus("test", Connection = "ServiceBusConnection")]
        public static string Run([BlobTrigger("samples-workitems/{name}", Connection = "str")]Stream myBlob, string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
            string a = "111111111111111";
            return a;
        }
    }
}

This is my local settings:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=lti/ThmF+mw9BebOacp9gVazIh76Q39ecikHSCkaTcGK5hmInspX+EkjzpNmvCPWsnvapWziHQHL+kKt2V+lZw==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "DefaultEndpointsProtocol=xxxxxx",
    "ServiceBusConnection": "Endpoint=sb://bowmantestxxxxxx"
  }
}

The str is from this place:

在此处输入图像描述

The ServiceBusConnection is from this place:

在此处输入图像描述

在此处输入图像描述

And please notice that the blob will will not be removed from container after the azure function is triggered. Also, dont forget to create at least one subscription in your service bus topic.

在此处输入图像描述

All all the above also works fine after the function be deployed to azure.(The difference from local is you need to add settings in configuration settings instead of local.settings.json)

在此处输入图像描述

在此处输入图像描述

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