azure - 处理来自不同 AD 租户中多个 Azure 订阅中存储帐户的 Blob 事件?

标签 azure azure-eventgrid

是否可以收到有关位于多个 Azure 订阅中的多个存储帐户中发生的 blobCreated 事件的通知?

我想处理在我的订阅中的中央 Azure 函数中的任意存储帐户中发生的 Blob 创建事件,但我希望客户能够将数据存储在他们自己的订阅中。

我正在考虑使用事件网格 Webhook 端点将事件路由到我的中央 Azure 函数。这是否是实现多订阅场景的可靠方法?

编辑:更准确地说,我需要它在不同的租户上工作(因为我们的客户会带来他们自己的订阅,我们需要集成它们而不将它们分配给我们的 AD 租户)

最佳答案

根据我们的讨论,以下屏幕片段显示了您的 Multi-Tenancy 粉丝场景。

跨 Azure 订阅( Multi-Tenancy )订阅分布式兴趣源是通过将主题映射到 Webhook 端点来完成的。请注意,该主题表示事件发布(发布)到 AEG 服务的位置的完整资源路径 (id)。该路径在当前租户的范围内,参见以下示例:

"topic": "/subscriptions/myID/resourceGroups/myRG/providers/microsoft.storage/storageaccounts/mySA"

"endpointBaseUrl": "https://myFnc.azurewebsites.net/runtime/webhooks/EventGrid?functionName=myEventGridTrigger&code=xxxx"

此映射在存储在与主题相同范围内的订阅元数据中声明。另一方面,Webhook 端点可以发布到此范围之外。

enter image description here

其他更复杂的解决方案以及使用扇出发布/订阅方式的事件分发与租户的完全隔离如以下屏幕片段所示:

enter image description here

在上述解决方案中,扇入订阅者可以将原始事件消息调解为正确的面向业务的事件消息,包括用于访问 blob 元数据和/或正文等的短 sasToken。

要使用 EventGridTrigger 函数的事件处理程序在租户中创建事件订阅,您可以使用 REST API call 等。 ,请参见以下示例:

   PUT https://management.azure.com/subscriptions/myId/resourceGroups/myRG/providers/Microsoft.Storage/storageaccounts/mySA/providers/Microsoft.EventGrid/eventSubscriptions/mySubscription?api-version=2019-01-01

标题:

  Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhb....

主体(最小有效负载):

{
  "properties": {
    "destination": {
      "endpointType": "WebHook",
      "properties": {
        "endpointUrl": "https://myFnc.azurewebsites.net/runtime/webhooks/EventGrid?functionName=myEventGridTrigger&code=xxxxxxxx..."
      }
    }
  }
}

更新:

在隔离的 Multi-Tenancy 分布式事件架构中使用 Azure 事件网格 Pub/Sub 模型的另一种方式是其级联。 逻辑事件管道可以通过级联 Azure 事件网格来构建,例如使用自定义主题将一个 Azure 事件网格订阅到另一个事件网格。

以下屏幕片段显示了 Azure 事件网格级联的示例:

enter image description here

基于扇入到扇出模式的级联概念是通过以标准 Pub/Sub 方式将自定义主题端点订阅到另一个事件网格模型的 WebHook 事件处理程序来启用的。

请注意,Azure 事件网格没有用于相互级联(包括验证事件环回)的内置终结点。但是,以下步骤可以允许相互级联 Azure 事件网格。

  1. 使用 CustomInputSchema 创建自定义主题端点,例如:

    {
       "properties": {
          "inputSchema": "CustomEventSchema",
          "inputSchemaMapping": {
          "properties": {
            "id": {
              "sourceField": null
            },
            "topic": {
              "sourceField": null
            },
            "eventTime": {
               "sourceField": null
            },
            "eventType": {
               "sourceField": "myEventType",
               "defaultValue": "recordInserted"
            },
            "subject": {
               "sourceField": "subject",
               "defaultValue": "/myapp/vehicles/motorcycles"
            },
            "dataVersion": {
              "sourceField": null,
              "defaultValue": "1.0"
            }
        },
        "inputSchemaMappingType": "Json"
        }
      }
    }
    

    请注意,主题属性必须具有"sourceField": null,这对于自定义主题来说是可以的(不适用于事件域)。

  2. 对于 Webhook 事件处理程序端点,请在 URL 查询字符串中使用 aeg-sas-key,例如:

    https://myTopic.westus-1.eventgrid.azure.net/api/events?aeg-sas-key=xxxxxxxxxx

    请注意,aeg-sas-key 值必须是 url 编码的字符串。

  3. 对于订阅验证,使用“即发即忘”方式的 validationUrl 握手。它可以在EventGridTrigger函数中实现并订阅自定义主题以实现级联目的。 以下代码片段显示了此实现的示例:

    #r "Newtonsoft.Json"
    
    using System;
    using System.Threading.Tasks;
    using System.Text;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    public static async Task Run(JObject eventGridEvent, ILogger log)
    {
       log.LogInformation(eventGridEvent.ToString());
    
       string eventType = $"{eventGridEvent["data"]?["eventType"]?.Value<string>()}";
       if(!string.IsNullOrEmpty(eventType) && eventType == "Microsoft.EventGrid.SubscriptionValidationEvent")
       {
          // manual validation
          string validationUrl = $"{eventGridEvent["data"]?["data"]?["validationUrl"]?.Value<string>()}";
          using (var client = new HttpClient())
          {
            var response = await client.GetAsync(validationUrl);
            log.LogInformation(response.ToString());
          }
       }
       else
       {
         // notifications
       }
    
       await Task.CompletedTask;
    }
    

    请注意,每次发布时,原始事件消息(原始源兴趣)都会级联(嵌套)在事件数据对象中

关于azure - 处理来自不同 AD 租户中多个 Azure 订阅中存储帐户的 Blob 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55342241/

相关文章:

Windows 任务计划程序报告不正确/不一致的结果代码

Azure Blob 存储 : 400 (One of the request inputs is out of range.)

c# - 在 Azure 移动服务项目和 Asp.Net MVC 项目之间共享数据库

azure - 如何监视 Azure 存储容器/子文件夹中 Blob 的创建并触发逻辑应用发送电子邮件

Azure 事件网格函数触发器 - 试用期

azure - ADF - 在管道 1 上触发管道 2 成功完成

sql-server - ActiveRecord(无 Rails): How to configure a connection to an azure database

asp.net-mvc-3 - 通过浏览器操作基于Azure的Office文档

azure - 在 azure 中,我应该在哪里添加电子邮件端点以从 azure 自动化 Runbook 发送结果?

java - Azure 函数、azureFunctionsPackage 任务因 java.lang.NullPointerException 失败