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

时间:2015-12-17 16:30:34

标签: azure azureservicebus azure-resource-manager

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

  

资源Microsoft.ServiceBus / namespaces / authorizationRules   'myservicebusnamespace / SendOnlyKey'失败,消息'请求   有效载荷不是预期的格式。

首先这可能吗?那里没有样品并做文件......

由于这是非常通用的消息,我想知道是否有其他人使用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]"
    }
  }
}

2 个答案:

答案 0 :(得分:1)

听起来像应该生成密钥的子模板失败了。

您可以尝试使用以下方法生成密钥吗?而改为PowerShell:

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

查看是否可以修复错误。

答案 1 :(得分:0)

困难的东西,这是肯定的。看看