[英]How to use Azurite blob containers as Azure Function internal storage and as trigger?
I've followed the instructions to download and install Azurite for Linux (Ubuntu 18.04).我已按照说明为 Linux (Ubuntu 18.04) 下载并安装 Azurite。 I want to use it with Azure Storage Explorer (also downloaded and installed) to visually manage/test an Azure Function with BlobTrigger.
我想将它与 Azure Storage Explorer(也已下载并安装)一起使用,以使用 BlobTrigger 直观地管理/测试 Azure Function。 I understand how to start Azurite and can upload blobs to an emulator container using Storage Exporer.
我了解如何启动 Azurite 并可以使用 Storage Exporer 将 blob 上传到模拟器容器。
Cannot figure out:无法弄清楚:
How to connect an Azure Function to an Azurite container to use as the Functions internal storage.如何将 Azure Function 连接到 Azurite 容器以用作函数内部存储。
a.一种。 I used
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
in local.settings.json
, but I don't see how that connects the Function to a given container in Azurite我在
local.settings.json
中使用"AzureWebJobsStorage": "UseDevelopmentStorage=true"
,但我看不到它如何将 Function 连接到 Azurite 中的给定容器
How to connect the Function to an Azurite container for BlobTrigger functionality.如何将 Function 连接到 Azurite 容器以实现BlobTrigger功能。
a.一种。 Do I need to add a
"BlobTrigger": "<azuriteContainerConnectionString>"
setting to local.settings.json
?我是否需要将
"BlobTrigger": "<azuriteContainerConnectionString>"
设置添加到local.settings.json
?
Basically, The Values in local.settings.json is been used to save the environment variable.基本上,local.settings.json 中的值用于保存环境变量。
The connection string is been declared in function.json.连接字符串在 function.json 中声明。 If you are using some language like C# or Java(Languages that need to be compiled, not run directly.), then it always have a declaration part, the declaration part will be convent to function.json after compiled.
如果你使用的是C#或Java(需要编译的语言,不能直接运行的语言),那么它总是有一个声明部分,编译后声明部分将转换为function.json。
I start a Azurite on local, and I try to use the default storage account:我在本地启动 Azurite,并尝试使用默认存储帐户:
I get the default connection string of blob service:我得到了 blob 服务的默认连接字符串:
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
And I create a C# azure function with blobtrigger:我用 blobtrigger 创建了一个 C# azure function:
local.settings.json 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;"
}
}
Function1.cs函数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");
}
}
}
It seems works fine:它似乎工作正常:
I set AzureWebJobsStorage
to a storage on azure because 10000 port is been used.我将 AzureWebJobsStorage 设置为
AzureWebJobsStorage
上的存储,因为使用了 10000 端口。
This is the doc:这是文档:
https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=/azure/storage/blobs/toc.json
Using the Microsoft Azure Storage Explorer to manage queueing, the following settings will work.使用 Microsoft Azure 存储资源管理器管理队列,以下设置将起作用。
(In this case the framework used was .net 5). (在这种情况下,使用的框架是 .net 5)。
Its not particularly obvious but you must set the connection string to use the value "UseDevelopmentStorage=true"它不是特别明显,但您必须将连接字符串设置为使用值“UseDevelopmentStorage=true”
My local.settings.json file after creating a new function我的 local.settings.json 文件新建后 function
My function
我的 function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.