使用死信存储更新Azure事件网格功能订阅

时间:2018-07-31 11:37:09

标签: azure-eventgrid

我在资源组receivingtestwesteurope下名为omni-test的存储帐户上成功创建了创建存储Blob的事件触发器,该触发器通过名为ValidateMetadata的函数接收。我是通过门户GUI创建的。但是,我现在想添加死信/重试策略,只能通过CLI来完成。

工作触发器如下:

{
    "destination": {
      "endpointBaseUrl": "https://omnireceivingprocesstest.azurewebsites.net/admin/extensions/EventGridExtensionConfig",
      "endpointType": "WebHook",
      "endpointUrl": null
    },
    "filter": {
      "includedEventTypes": [
        "Microsoft.Storage.BlobCreated"
      ],
      "isSubjectCaseSensitive": null,
      "subjectBeginsWith": "/blobServices/default/containers/snapshots/blobs/",
      "subjectEndsWith": ".png"
    },
    "id": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/Microsoft.Storage/StorageAccounts/receivingtestwesteurope/providers/Microsoft.EventGrid/eventSubscriptions/png",
    "labels": [
      ""
    ],
    "name": "png",
    "provisioningState": "Succeeded",
    "resourceGroup": "omni-test",
    "topic": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope",
    "type": "Microsoft.EventGrid/eventSubscriptions"
}

首先,我认为我可以使用死信队列更新现有事件:

az eventgrid event-subscription update --name png --deadletter-endpoint receivingtestwesteurope/blobServices/default/containers/eventgrid

哪个返回:

  

az:错误:无法识别的参数:--deadletter-endpoint   receivetestwesteurope / blobServices / default / containers / eventgrid

然后我通过REST修补程序尝试了

https://docs.microsoft.com/en-us/rest/api/eventgrid/eventsubscriptions/update

  • 范围:/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope
  • eventSubscriptionName:png
  • api版本:2018-05-01-preview

身体:

"deadletterdestination": {
  "endpointType": "StorageBlob",
  "properties": {
    "blobContainerName": "eventgrid",
    "resourceId": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope"
  }}

返回哪个

  

“模型状态无效。”

==================

最终的解决方案:

{
    "deadletterdestination": {
        "endpointType": "StorageBlob",
        "properties": {
            "blobContainerName": "eventgrid",
            "resourceId": "/subscriptions/fa6409ab-1234-1234-1234-85dd2b3ceab4/resourceGroups/omni-test/providers/microsoft.storage/storageaccounts/receivingtestwesteurope"
        }
    }
}

1 个答案:

答案 0 :(得分:1)

查看Manage Event Grid delivery settings,其中详细介绍了启用死信的方法。注意,您必须安装eventgrid扩展

az扩展名添加--name eventgrid

此外,您可以使用REST API来更新事件订阅以进行死信。

此外,我刚刚发布了精巧的工具Azure Event Grid Tester,以帮助在本地计算机上使用Azure事件网格模型。

更新

以下是 deadletterdestination 属性:

"deadletterdestination": {
  "endpointType": "StorageBlob",
  "properties": {
    "blobContainerName": "{containerName}",
    "resourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resgroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}"
   }
 }

您可以将Event Subscriptions - Update(REST API PATCH)与上述属性一起使用。请注意,必须使用 api-version = 2018-05-01-preview