使用 Resource Manager 範本在 Azure 事件方格中建立系統主題
本文說明如何使用 Resource Manager 範本來建立和管理系統主題。 如需系統主題的概觀,請參閱系統主題。
先建立系統主題,然後建立事件訂閱
若要先在 Azure 來源上建立系統主題,然後為該主題建立事件訂閱,您可以使用類似下列的範本:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageName": {
"type": "string",
"defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Provide a unique name for the Blob Storage account."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Provide a location for the Blob Storage account that supports Event Grid."
}
},
"eventSubName": {
"type": "string",
"defaultValue": "subToStorage",
"metadata": {
"description": "Provide a name for the Event Grid subscription."
}
},
"endpoint": {
"type": "string",
"metadata": {
"description": "Provide the URL for the WebHook to receive events. Create your own endpoint for events."
}
},
"systemTopicName": {
"type": "String",
"defaultValue": "mystoragesystemtopic",
"metadata": {
"description": "Provide a name for the system topic."
}
}
},
"resources": [
{
"name": "[parameters('storageName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-10-01",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"location": "[parameters('location')]",
"tags": {},
"properties": {
"accessTier": "Hot"
}
},
{
"name": "[parameters('systemTopicName')]",
"type": "Microsoft.EventGrid/systemTopics",
"apiVersion": "2020-04-01-preview",
"location": "[parameters('location')]",
"dependsOn": [
"[parameters('storageName')]"
],
"properties": {
"source": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]",
"topicType": "Microsoft.Storage.StorageAccounts"
}
},
{
"type": "Microsoft.EventGrid/systemTopics/eventSubscriptions",
"apiVersion": "2020-04-01-preview",
"name": "[concat(parameters('systemTopicName'), '/', parameters('eventSubName'))]",
"dependsOn": [
"[resourceId('Microsoft.EventGrid/systemTopics', parameters('systemTopicName'))]"
],
"properties": {
"destination": {
"properties": {
"endpointUrl": "[parameters('endpoint')]"
},
"endpointType": "WebHook"
},
"filter": {
"includedEventTypes": [
"Microsoft.Storage.BlobCreated",
"Microsoft.Storage.BlobDeleted"
]
}
}
}
]
}
請參閱使用 Azure Resource Manager 範本將 Blob 儲存體事件路由至 Web 端點,取得使用 Resource Manager 範本建立系統主題和訂閱的指示。
建立事件訂閱戶時建立系統主題
若要隱含建立系統主題,在 Azure 來源上建立事件訂閱時,您可以使用下列範本:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageName": {
"type": "string",
"defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Provide a unique name for the Blob Storage account."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Provide a location for the Blob Storage account that supports Event Grid."
}
},
"eventSubName": {
"type": "string",
"defaultValue": "subToStorage",
"metadata": {
"description": "Provide a name for the Event Grid subscription."
}
},
"endpoint": {
"type": "string",
"metadata": {
"description": "Provide the URL for the WebHook to receive events. Create your own endpoint for events."
}
}
},
"resources": [
{
"name": "[parameters('storageName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-10-01",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"location": "[parameters('location')]",
"tags": {},
"properties": {
"accessTier": "Hot"
}
},
{
"type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
"name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
"apiVersion": "2018-01-01",
"dependsOn": [
"[parameters('storageName')]"
],
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "[parameters('endpoint')]"
}
},
"filter": {
"subjectBeginsWith": "",
"subjectEndsWith": "",
"isSubjectCaseSensitive": false,
"includedEventTypes": [
"All"
]
}
}
}
]
}
下一步
若要深入了解 Azure 事件方格所支援的系統主題和主題類型,請參閱 Azure 事件方格中的系統主題一節。