在 Azure 服务总线基本和标准层中启用分区

服务总线分区允许跨多个消息中转站对队列和主题或消息实体进行分区。 分区意味着分区实体的总吞吐量不再受单个消息中转站的性能所限制。 此外,消息中转站的临时服务中断(例如在升级期间)不会呈现分区队列或主题不可用。 分区队列和主题可以包含所有先进的服务总线功能,如事务和会话支持。 有关详细信息,请参阅分区队列和主题。 本文介绍为服务总线队列或主题启用重复消息检测的不同方式。

重要

  • 分区在为基本或标准 SKU 中的所有队列和主题创建实体时可用。
  • 不能更改任何现有队列或主题中的分区选项。 只能在创建队列或主题时设置选项。
  • 在标准层命名空间中,可创建 1、2、3、4 或 5 GB 大小的服务总线队列和主题(默认值为 1 GB)。 启用分区后,服务总线将创建实体的 16 个副本(16 个分区),每个副本具有指定的相同大小。 因此,如果你创建了一个大小为 5 GB 的队列,共有 16 个分区,最大队列大小为 (5 * 16) = 80 GB。

使用 Azure 门户

在 Azure 门户中创建“队列”时,请选择“启用分区”,如下图所示。

Enable partitioning at the time of the queue creation

在 Azure 门户中创建主题时,请选择“启用分区”,如下图所示。

Enable partitioning at the time of the topic creation

使用 Azure CLI

若要创建已启用分区的队列,请使用 --enable-partitioning 设置为 trueaz servicebus queue create 命令。

az servicebus queue create \
    --resource-group myresourcegroup \
    --namespace-name mynamespace \
    --name myqueue \
    --enable-partitioning true

若要创建已启用分区的主题,请使用 --enable-partitioning 设置为 trueaz servicebus topic create 命令。

az servicebus topic create \
    --resource-group myresourcegroup \
    --namespace-name mynamespace \
    --name mytopic \
    --enable-partitioning true

使用 Azure PowerShell

若要创建已启用分区的队列,请使用 -EnablePartitioning 设置为 $TrueNew-AzServiceBusQueue 命令。

New-AzServiceBusQueue -ResourceGroup myresourcegroup `
    -NamespaceName mynamespace `
    -QueueName myqueue `
    -EnablePartitioning $True

若要创建已启用分区的主题,请使用 -EnablePartitioning 设置为 trueNew-AzServiceBusTopic 命令。

New-AzServiceBusTopic -ResourceGroup myresourcegroup `
    -NamespaceName mynamespace `
    -Name mytopic `
    -EnablePartitioning $True

使用 Azure Resource Manager 模板

若要创建已启用分区的队列,请在“队列属性”部分中将 enablePartitioning 设置为 true。 有关详细信息,请参阅 Microsoft.ServiceBus 命名空间/队列模板参考

{
  "$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."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.ServiceBus/namespaces",
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('serviceBusNamespaceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {},
      "resources": [
        {
          "type": "Queues",
          "apiVersion": "2017-04-01",
          "name": "[parameters('serviceBusQueueName')]",
          "dependsOn": [
            "[resourceId('Microsoft.ServiceBus/namespaces', parameters('serviceBusNamespaceName'))]"
          ],
          "properties": {
            "enablePartitioning": true
          }
        }
      ]
    }
  ]
}

若要创建已启用重复检测的主题,请在“主题属性”部分中将 enablePartitioning 设置为 true。 有关详细信息,请参阅 Microsoft.ServiceBus 命名空间/主题模板参考

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "service_BusNamespace_Name": {
      "type": "string",
      "metadata": {
        "description": "Name of the Service Bus namespace"
      }
    },
    "serviceBusTopicName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Topic"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('service_BusNamespace_Name')]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {},
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('serviceBusTopicName')]",
          "type": "topics",
          "dependsOn": [
            "[resourceId('Microsoft.ServiceBus/namespaces/', parameters('service_BusNamespace_Name'))]"
          ],
          "properties": {
            "enablePartitioning": true
          }
        }
      ]
    }
  ]
}

后续步骤

尝试采用所选语言的示例,了解 Azure 服务总线功能。

在下面查找早期 .NET 和 Java 客户端库示例:

注意

2026 年 9 月 30 日,我们将停用 Azure 服务总线 SDK 库 WindowsAzure.ServiceBus、Microsoft.Azure.ServiceBus 和 com.microsoft.azure.servicebus,这些库不符合 Azure SDK 准则。 我们还将结束对 SBMP 协议的支持,因此在 2026 年 9 月 30 日之后,你将无法再使用此协议。 请在该日期之前迁移到最新的 Azure SDK 库,新库提供了关键安全更新和改进功能。

尽管旧库在 2026 年 9 月 30 日之后仍可使用,但它们将不再获得 Azure 的官方支持和更新。 有关详细信息,请参阅支持停用公告