简体   繁体   English

Azure 存储 Blob 触发器未唤醒睡眠 function

[英]Azure Storage Blob Trigger is not awakening a sleeping function

This question is similar to Azure Blob Storage trigger Function not firing这个问题类似于Azure Blob 存储触发器 Function 未触发

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.然而,他们的问题是他们的 Azure Function 并没有立即醒来,给人的印象是它没有处理来自 Azure Blob Storage 的触发器,这正是它声称的事实。

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp 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.我的 blob 现在已经在容器中放置了 9 个小时,但仍未处理。

All it does is post a message onto ServiceBus.它所做的只是在 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.现在,9 小时后,我重新启动了 function 应用程序,并且在大约 10 分钟内处理了 blob。

Update:更新:

Thanks for Peter Morris's sharing, the problem comes from is service plan is d1.感谢彼得莫里斯的分享,问题出在服务计划是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.当我们使用 azure function 时,即使只是测试,我们也应该使用消耗计划。 The smallest in production is S1, which is normally used for testing.生产中最小的是 S1,通常用于测试。

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: str 来自这个地方:

在此处输入图像描述

The ServiceBusConnection is from this place: ServiceBusConnection 来自这个地方:

在此处输入图像描述

在此处输入图像描述

And please notice that the blob will will not be removed from container after the azure function is triggered.请注意,在触发 azure function 后,blob 不会从容器中删除。 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)在将 function 部署到 azure 之后,上述所有操作也可以正常工作。(与本地的区别是您需要在配置设置中添加设置而不是 local.settings.json)

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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