6

我已按照说明下载并安装 Azurite for Linux (Ubuntu 18.04)。我想将它与 Azure 存储资源管理器(也已下载并安装)一起使用,以通过 BlobTrigger 直观地管理/测试 Azure 函数。我了解如何启动 Azurite 并可以使用 Storage Exporer 将 blob 上传到模拟器容器。

想不通:

  1. 如何将 Azure Function 连接到 Azurite 容器以用作 Functions内部存储。

    一个。我在 中使用"AzureWebJobsStorage": "UseDevelopmentStorage=true"local.settings.json,但我看不到它如何将函数连接到 Azurite 中的给定容器

  2. 如何将函数连接到 Azurite 容器以实现BlobTrigger功能。

    一个。我需要添加"BlobTrigger": "<azuriteContainerConnectionString>"设置local.settings.json吗?

4

1 回答 1

4

基本上,local.settings.json 中的值用于保存环境变量。

连接字符串在 function.json 中声明。如果你使用的是 C# 或 Java 之类的语言(需要编译的语言,不能直接运行。),那么它总是有一个声明部分,声明部分将在编译后转换为 function.json。

我在本地启动 Azurite,并尝试使用默认存储帐户:

我得到 blob 服务的默认连接字符串:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;

我用 blobtrigger 创建了一个 C# azure 函数:

local.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
  }
}

函数1.cs

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

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("test/{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");
        }
    }
}

它似乎工作正常:

在此处输入图像描述

因为使用了 10000 端口,所以我设置AzureWebJobsStorage为 azure 上的存储。

这是文档:

https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=/azure/storage/blobs/toc.json
于 2020-09-21T07:18:15.607 回答