Azure ServiceBus - 队列 - 授权规则创建错误

Azure ServiceBus - Queue - Authorization rule creation error

我正在使用 ServiceBus、队列和一对共享访问规则创建 Azure 资源管理器模板。我正在正确创建命名空间和队列,但是当我尝试添加授权规则时,我得到:

Resource Microsoft.ServiceBus/namespaces/authorizationRules 'myservicebusnamespace/SendOnlyKey' failed with message 'Request payload is not in the expected format.

首先这可能吗?那里没有样本,也没有做文档..

由于这是非常笼统的消息,我想知道是否还有其他人在使用 ARM 模板创建队列时遇到过类似问题? 这是我目前所拥有的:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sbNamespace": {
      "type": "string",
      "metadata": {
        "description": "The service bus namespace"
      }
    }
  },
  "variables": {
    "location": "[resourceGroup().location]",
    "sbVersion": "[providers('Microsoft.ServiceBus', 'namespaces').apiVersions[0]]",
    "queueName": "testQueue",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('sbNamespace'), variables('defaultSASKeyName'))]",
    "sendAuthRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('sbNamespace'), 'SendOnlyKey')]",
    "keyGeneratorTemplateUri": "https://raw.githubusercontent.com/sjkp/Azure.ARM.ServiceBus/master/Azure.ARM.ServiceBus/Templates/keygenerator.json"
  },
  "resources": [
    {
      "apiVersion": "2015-01-01",
      "name": "primaryKey",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "incremental",
        "templateLink": {
          "uri": "[variables('keyGeneratorTemplateUri')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "seed": { "value": "1234a5" }
        }
      }
    },
    {
      "apiVersion": "2015-01-01",
      "name": "secondaryKey",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "incremental",
        "templateLink": {
          "uri": "[variables('keyGeneratorTemplateUri')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "seed": { "value": "ac34a5" }
        }
      }
    },
    {
      //namespace
      "apiVersion": "[variables('sbVersion')]",
      "name": "[parameters('sbNamespace')]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[variables('location')]",
      "properties": {
        "messagingSku": 2
      },
      "resources": [
        {
          //queue
          "apiVersion": "[variables('sbVersion')]",
          "name": "[variables('queueName')]",
          "type": "Queues",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('sbNamespace'))]"
          ],
          "properties": {
            "path": "[variables('queueName')]",
            "defaultMessageTimeToLive": "14.0:0:0",
            "maxQueueSizeInMegaBytes": "1024",
            "maxDeliveryCount": "10"
          }
        }
        ,{
          //auth rule 1
          "apiVersion": "[variables('sbVersion')]",
          "name": "[concat(parameters('sbNamespace'),'/SendOnlyKey')]",
          "type": "Microsoft.ServiceBus/namespaces/authorizationRules",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('sbNamespace'))]",
            "[concat('Microsoft.Resources/deployments/', 'primaryKey')]",
            "[concat('Microsoft.Resources/deployments/', 'secondaryKey')]"
          ],
          "location": "[variables('location')]",
          "properties": {
            "keyName": "SendOnlyKey",
            "PrimaryKey": "[reference('primaryKey').outputs.key.value]",
            "SecondaryKey": "[reference('secondaryKey').outputs.key.value]"
          }
        }
      ]
    }
  ],
  "outputs": {
    "NamespaceDefaultConnectionString": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
    }
  }
}

困难的事情,这是肯定的。看看

听起来应该生成密钥的子模板出现问题。

您可以尝试使用例如powershell 改为:

$bytes = New-Object Byte[] 32
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rand.GetBytes($bytes)
$rand.Dispose()
$key = [System.Convert]::ToBase64String($bytes)

查看是否修复了错误。