快速入门:使用 ARM 模板创建服务总线命名空间和队列Quickstart: Create a Service Bus namespace and a queue using an ARM template

本文介绍如何使用创建服务总线命名空间和命名空间中队列的 Azure 资源管理器模板(ARM 模板)。This article shows how to use an Azure Resource Manager template (ARM template) that creates a Service Bus namespace and a queue within that namespace. 本文介绍如何指定要部署的资源以及如何定义执行部署时指定的参数。The article explains how to specify which resources are deployed and how to define parameters that are specified when the deployment is executed. 可将此模板用于自己的部署,或自定义此模板以满足要求。You can use this template for your own deployments, or customize it to meet your requirements.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 Azure Deploy to Azure

先决条件Prerequisites

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "serviceBusNamespaceName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Service Bus namespace"
      }
    },
    "serviceBusQueueName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Queue"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('serviceBusNamespaceName'), variables('defaultSASKeyName'))]",
    "sbVersion": "2017-04-01"
  },
  "resources": [
    {
      "apiVersion": "2017-04-01",
      "name": "[parameters('serviceBusNamespaceName')]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {},
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('serviceBusQueueName')]",
          "type": "Queues",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceName'))]"
          ],
          "properties": {
            "lockDuration": "PT5M",
            "maxSizeInMegabytes": "1024",
            "requiresDuplicateDetection": "false",
            "requiresSession": "false",
            "defaultMessageTimeToLive": "P10675199DT2H48M5.4775807S",
            "deadLetteringOnMessageExpiration": "false",
            "duplicateDetectionHistoryTimeWindow": "PT10M",
            "maxDeliveryCount": "10",
            "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",
            "enablePartitioning": "false",
            "enableExpress": "false"
          }
        }
      ]
    }
  ],
  "outputs": {
    "NamespaceConnectionString": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
    },
    "SharedAccessPolicyPrimaryKey": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryKey]"
    }
  }
}

该模板中定义的资源包括:The resources defined in the template include:

可以从 Azure 快速入门模板中找到更多模板You can find more template from Azure Quickstart Templates

部署模板Deploy the template

使用此模板,将部署包含队列的服务总线命名空间。With this template, you deploy a Service Bus namespace with a queue.

服务总线队列为一个或多个竞争使用方提供先入先出 (FIFO) 消息传送方式。Service Bus queues offer First In, First Out (FIFO) message delivery to one or more competing consumers.

若要自动运行部署,请单击以下按钮:为部署创建新的资源组,以便稍后可以轻松进行清理。To run the deployment automatically, click the following button: Create a new resource group for the deployment so that you can easily cleanup later.

部署到 Azure Deploy to Azure

验证部署Validate the deployment

  1. 选择顶部的“通知”,查看部署状态。Select Notifications at the top to see the status of the deployment. 等待部署成功。Wait until the deployment succeeds. 然后,在通知消息中选择“转到资源组”,导航到包含服务总线命名空间的资源组的页面。Then, select Go to resource group in the notification message to navigate to the page for the resource group that contains the Service Bus namespace.

    来自部署的通知

  2. 确认在资源列表中看到了服务总线命名空间。Confirm that you see your Service Bus namespace in the list of resources.

    资源组 - 命名空间

  3. 从列表中选择命名空间以查看“服务总线命名空间”页。Select the namespace from the list to see the Service Bus Namespace page.

清理资源Clean up resources

  1. 在 Azure 门户中,导航到资源组的“资源组”页。In the Azure portal, navigate to the Resource group page for your resource group.

  2. 从工具栏选择删除资源组Select Delete resource group from the toolbar.

  3. 键入资源组的名称,然后选择“删除”。Type the name of the resource group, and select Delete.

    资源组 - 删除

后续步骤Next steps

请参阅以下主题,其中介绍了如何创建命名空间/队列的授权规则:See the following topic that shows how to create an authorization rule for the namespace/queue:

使用 ARM 模板为命名空间和队列创建服务总线授权规则Create a Service Bus authorization rule for namespace and queue using an ARM template

查看以下文章了解如何管理这些资源:Learn how to manage these resources by viewing these articles: