azure - 如何将 Azure Eventhub 主要和辅助连接 key 作为 ARM 模板输出返回?

标签 azure azure-eventhub azure-rm-template

我已准备好用于部署 Azure Eventhub 实例的 ARM 模板,但想知道如何访问两个连接 key 以将它们作为输出返回?

portal screenshot

我想返回以下形式的字符串:

Endpoint=sb://my-eventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=ojZMQcJD7uYifxJyGeXG6tNDdZyaC1/h5tmX6ODVfmY=

这是我当前的模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "clusterName": {
            "type": "string",
            "defaultValue": "eventhub",
            "metadata": {
                "description": "Name for the Event Hub cluster."
            }
        },
        "namespaceName": {
            "type": "string",
            "defaultValue": "namespace",
            "metadata": {
                "description": "Name for the Namespace to be created in cluster."
            }
        }
    },
    "variables": {
        "clusterName": "[concat(resourceGroup().name, '-', parameters('clusterName'))]",
        "namespaceName": "[concat(resourceGroup().name, '-', parameters('namespaceName'))]"
    },
    "outputs": {
        "MyClusterName": {
            "type": "string",
            "value": "[variables('clusterName')]"
        },
        "PrimaryConnectionString": {
            "type": "string",
            "value": "WHAT TO USE HERE PLEASE?"
        },
        "SecondaryConnectionString": {
            "type": "string",
            "value": "WHAT TO USE HERE PLEASE?"
        }
    },
    "resources": [
        {
            "type": "Microsoft.EventHub/clusters",
            "apiVersion": "2018-01-01-preview",
            "name": "[variables('clusterName')]",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "Dedicated",
                "capacity": 1
            }
        },
        {
            "type": "Microsoft.EventHub/namespaces",
            "apiVersion": "2018-01-01-preview",
            "name": "[variables('namespaceName')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/clusters', variables('clusterName'))]"
            ],
            "sku": {
                "name": "Standard",
                "tier": "Standard",
                "capacity": 1
            },
            "properties": {
                "isAutoInflateEnabled": false,
                "maximumThroughputUnits": 0,
                "clusterArmId": "[resourceId('Microsoft.EventHub/clusters', variables('clusterName'))]"
            }
        }
    ]
}

我尝试过以下方法:

"value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/AuthorizationRules'), variables('namespaceName'), 'RootManageSharedAccessKey'),'2018-01-01-preview').primaryConnectionString]"

但出现部署错误:

[error]ParentResourceNotFound: Can not perform requested operation on nested resource. Parent resource 'my-rg-namespace' not found.

更新:

按照杰西的建议,以下内容对我有用(谢谢!):

"variables": {
    "clusterName": "[concat(resourceGroup().name, '-', parameters('clusterName'))]",
    "namespaceName": "[concat(resourceGroup().name, '-', parameters('namespaceName'))]",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', variables('namespaceName'), variables('defaultSASKeyName'))]"
},
"outputs": {
    "MyClusterName": {
        "type": "string",
        "value": "[variables('clusterName')]"
    },
    "PrimaryConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), '2015-08-01').primaryConnectionString]"
    },
    "SecondaryConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), '2015-08-01').secondaryConnectionString]"
    }
},

更新2:

此外,Jesse 注意到我的 ARM 模板在两个方面是错误的,因为它没有创建事件中心,而是创建了一个集群,并且它位于我的命名空间之外,并提供了以下宝贵的评论:

The Event Hubs cluster is basically a way of reserving dedicated compute. It's not something that most scenarios need and it is... not cheap. Think of something on the scale of Xbox Live where you're seeing nearly 5 millions of events per second and which have higher performance needs. If you're not looking at that kind of scale or that sensitivity around timing, you probably want to rethink the need for a dedicated cluster.

Normally, you'd just provision an Event Hubs namespace which will use shared infrastructure with certain guarantees to minimize noisy neighbors and similar. This is adequate for the majority of scenarios, even those with high throughput needs. If you're not sure, this is probably the place that you want to start and then upgrade to a dedicated cluster if your needs justify the cost.

An Event Hubs namespace is the container for a set of Event Hub instances grouped together by a unique endpoint. Each Event Hub is made of a set of partitions. When you're publishing or consuming events, the partitions of an Event Hub are where the actual data is. When you're working with one of the SDKs, you'll start by telling it about the endpoint of your namespace and the Event Hub that you're interested in. You'll need a general awareness of partitions, but most of the "Getting Started" scenarios handle that detail for you, as do a fair portion of the real-world ones.... but, the concept is an important one.

最佳答案

看起来您可能使用了不正确的资源 ID,从 Microsoft.ServiceBus 提取,而不是从 Microsoft.EventHub 提取,失败的原因是没有服务总线命名空间具有正确的名称。

您可能需要尝试使用类似于以下的表单来识别您的资源:

"variables": {                
    "location": "[resourceGroup().location]",
    "apiVersion": "2015-08-01",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', parameters('namespaceName'), variables('defaultSASKeyName'))]"
},

这应该允许使用 listkeys 返回它,正如您在上面详细说明的那样:

"outputs": {
    "NamespaceConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), variables('apiVersion')).primaryConnectionString]"
    }
}

简单部署的完整示例可以在 Event Hubs sample template 中找到。 .

关于azure - 如何将 Azure Eventhub 主要和辅助连接 key 作为 ARM 模板输出返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62115244/

相关文章:

azure - 使用 Azure 事件中心 API 时是否有任何方法可以验证事件有效负载架构?

azure - 如何增加azure中纪元的大小

azure - 为什么某些 Azure Eventhub 记录中有 2 个事件?

Azure 日志分析。使用 ARM 模板创建警报规则

azure - CRM 2016 在线和 Azure 服务总线中继 - 50200 : Bad Gateway

azure - 在 Azure Monitor 工作簿中针对资源管理器创建查询时出现错误消息

Azure 应用服务高级版 - 保护内部服务

python-3.x - ansible 剧本错误为 : ModuleNotFoundError: No module named 'azure.mgmt.monitor.version' although the module is installed

azure - 条件语句不适用于虚拟机扩展

azure - 如何在 ARM 模板中动态生成流量管理器端点?