具有两个输出绑定的Azure函数(Azure队列& blob存储)

发布于 2025-02-04 02:21:05 字数 78 浏览 2 评论 0 原文

是否可以使用两个输出绑定来编写Azure HTTP触发功能,以便数据不仅输出到Azure队列,还将相同的消息发送到Azure Blob存储中?

Is it possible to write an azure http trigger function with two output bindings, so that data not only outputs to an azure queue but also sends the same message to an azure blob storage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヅ她的身影、若隐若现 2025-02-11 02:21:05

请在此处找到多个出站绑定的样本:

    public async Task<IActionResult> Sample(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "sample")] HttpRequest req,
[Queue("sample", Connection = "StorageAccountString")] CloudQueue sampleQueue,
[Blob("sample", FileAccess.Read, Connection = "StorageAccountString")] CloudBlobContainer sampleContainer,
ExecutionContext context,
ILogger log)
    {
        var requestBody = await req.ReadAsStringAsync().ConfigureAwait(false);

        var queueMessage = new CloudQueueMessage(requestBody);
        await sampleQueue.AddMessageAsync(queueMessage).ConfigureAwait(false);

        CloudBlockBlob blob = sampleContainer.GetBlockBlobReference($"{Guid.NewGuid().ToString()}");
        blob.UploadText(requestBody);

        return new OkResult();
    }

在这里您可以找到多个Blob出站绑定:

https://learlen.microsoft.com/en-en-us/azure/azure/azure/azure-functions/functions/functions/functions -bindings-storage-blob-utput?tabs =过程中%2cextensionv5&amp; pivots =编程语言 - 语言csharp#example

**using System.Collections.Generic;
using System.IO;
using Microsoft.Azure.WebJobs;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

public class ResizeImages
{
    [FunctionName("ResizeImage")]
    public static void Run([BlobTrigger("sample-images/{name}")] Stream image,
        [Blob("sample-images-sm/{name}", FileAccess.Write)] Stream imageSmall,
        [Blob("sample-images-md/{name}", FileAccess.Write)] Stream imageMedium)
    {
        IImageFormat format;

        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageSmall, ImageSize.Small, format);
        }

        image.Position = 0;
        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageMedium, ImageSize.Medium, format);
        }
    }

    public static void ResizeImage(Image<Rgba32> input, Stream output, ImageSize size, IImageFormat format)
    {
        var dimensions = imageDimensionsTable[size];

        input.Mutate(x => x.Resize(dimensions.Item1, dimensions.Item2));
        input.Save(output, format);
    }

    public enum ImageSize { ExtraSmall, Small, Medium }

    private static Dictionary<ImageSize, (int, int)> imageDimensionsTable = new Dictionary<ImageSize, (int, int)>() {
        { ImageSize.ExtraSmall, (320, 200) },
        { ImageSize.Small,      (640, 400) },
        { ImageSize.Medium,     (800, 600) }
    };

}**

Please find a sample for multiple outbound bindings here:

    public async Task<IActionResult> Sample(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "sample")] HttpRequest req,
[Queue("sample", Connection = "StorageAccountString")] CloudQueue sampleQueue,
[Blob("sample", FileAccess.Read, Connection = "StorageAccountString")] CloudBlobContainer sampleContainer,
ExecutionContext context,
ILogger log)
    {
        var requestBody = await req.ReadAsStringAsync().ConfigureAwait(false);

        var queueMessage = new CloudQueueMessage(requestBody);
        await sampleQueue.AddMessageAsync(queueMessage).ConfigureAwait(false);

        CloudBlockBlob blob = sampleContainer.GetBlockBlobReference(
quot;{Guid.NewGuid().ToString()}");
        blob.UploadText(requestBody);

        return new OkResult();
    }

Here you can find multiple Blob outbound bindings:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=in-process%2Cextensionv5&pivots=programming-language-csharp#example

**using System.Collections.Generic;
using System.IO;
using Microsoft.Azure.WebJobs;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

public class ResizeImages
{
    [FunctionName("ResizeImage")]
    public static void Run([BlobTrigger("sample-images/{name}")] Stream image,
        [Blob("sample-images-sm/{name}", FileAccess.Write)] Stream imageSmall,
        [Blob("sample-images-md/{name}", FileAccess.Write)] Stream imageMedium)
    {
        IImageFormat format;

        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageSmall, ImageSize.Small, format);
        }

        image.Position = 0;
        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageMedium, ImageSize.Medium, format);
        }
    }

    public static void ResizeImage(Image<Rgba32> input, Stream output, ImageSize size, IImageFormat format)
    {
        var dimensions = imageDimensionsTable[size];

        input.Mutate(x => x.Resize(dimensions.Item1, dimensions.Item2));
        input.Save(output, format);
    }

    public enum ImageSize { ExtraSmall, Small, Medium }

    private static Dictionary<ImageSize, (int, int)> imageDimensionsTable = new Dictionary<ImageSize, (int, int)>() {
        { ImageSize.ExtraSmall, (320, 200) },
        { ImageSize.Small,      (640, 400) },
        { ImageSize.Medium,     (800, 600) }
    };

}**
神魇的王 2025-02-11 02:21:05

如果您在一个孤立的过程中运行函数应用程序,Microsoft在此处进行了简短的讨论和示例:

隔离过程 - 多个输出绑定

If you're running your function app in an isolated process, Microsoft has a brief discussion and example here:

Isolated process - Multiple output bindings

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文