如何将 Apache Kafka on HDInsight 配置为自动创建主题How to configure Apache Kafka on HDInsight to automatically create topics

默认情况下,HDInsight 上的 Apache Kafka 不允许自动创建主题。By default, Apache Kafka on HDInsight does not enable automatic topic creation. 可以使用 Apache Ambari 针对现有群集自动创建主题。You can enable auto topic creation for existing clusters using Apache Ambari. 也可以允许使用 Azure 资源管理器模板在创建新的 Kafka 群集时自动创建主题。You can also enable auto topic creation when creating a new Kafka cluster using an Azure Resource Manager template.

Apache Ambari Web UIApache Ambari Web UI

若要允许通过 Ambari Web UI 在现有的群集上自动创建主题,请执行以下步骤:To enable automatic topic creation on an existing cluster through the Ambari Web UI, use the following steps:

  1. Azure 门户选择 Kafka 群集。From the Azure portal, select your Kafka cluster.

  2. 群集仪表板中,选择“Ambari 主页” 。From Cluster dashboards, select Ambari home.

    群集仪表板处于选中状态的门户的图像

    出现提示时,进行身份验证使用群集的登录名 (admin) 凭据。When prompted, authenticate using the login (admin) credentials for the cluster. 或者,可以直接从 https://CLUSTERNAME.azurehdinsight.cn/ 连接到 Amabri,其中 CLUSTERNAME 是 Kafka 群集的名称。Alternatively, you can connect to Amabri directly from https://CLUSTERNAME.azurehdinsight.cn/ where CLUSTERNAME is the name of your Kafka cluster.

  3. 从页面左侧的列表选择 Kafka 服务。Select the Kafka service from the list on the left of the page.

    服务列表

  4. 在页面中间选择“配置”。Select Configs in the middle of the page.

    “服务配置”选项卡

  5. 在“筛选器”字段中输入值 auto.createIn the Filter field, enter a value of auto.create.

    筛选器字段图像

    这将筛选的属性,并显示列表auto.create.topics.enable设置。This filters the list of properties and displays the auto.create.topics.enable setting.

  6. auto.create.topics.enable 的值更改为 true,然后选择“保存” 。Change the value of auto.create.topics.enable to true, and then select Save. 添加注释,然后选择保存Add a note, and then select Save again.

    auto.create.topics.enable 条目的图像

  7. 依次选择 Kafka 服务、“重启”、“重启所有受影响的项”。 Select the Kafka service, select Restart, and then select Restart all affected. 出现提示时,选择“确认全部重启” 。When prompted, select Confirm restart all.

    重启选择的图像

Note

也可通过 Ambari REST API 设置 Ambari 值。You can also set Ambari values through the Ambari REST API. 这通常更为困难,因为需进行多次 REST 调用来检索并修改当前配置以及执行其他操作。有关详细信息,请参阅使用 Apache Ambari REST API 管理 HDInsight 群集文档。This is generally more difficult, as you have to make multiple REST calls to retrieve the current configuration, modify it, etc. For more information, see the Manage HDInsight clusters using the Apache Ambari REST API document.

Resource Manager 模板Resource Manager templates

使用 Azure 资源管理器模板创建 Kafka 群集时,可以将 auto.create.topics.enable 添加到 kafka-broker 中,对其直接进行设置。When creating a Kafka cluster using an Azure Resource Manager template, you can directly set auto.create.topics.enable by adding it in a kafka-broker. 以下 JSON 代码片段演示如何将此值设置为 trueThe following JSON snippet demonstrates how to set this value to true:

"clusterDefinition": {
    "kind": "kafka",
    "configurations": {
    "gateway": {
        "restAuthCredential.isEnabled": true,
        "restAuthCredential.username": "[parameters('clusterLoginUserName')]",
        "restAuthCredential.password": "[parameters('clusterLoginPassword')]"
    },
    "kafka-broker": {
        "auto.create.topics.enable": "true"
    }
}

后续步骤Next Steps

本文档介绍了如何为 HDInsight 上的 Apache Kafka 启用自动创建主题功能。In this document, you learned how to enable automatic topic creation for Apache Kafka on HDInsight. 若要详细了解如何使用 Kafka,请参阅以下链接:To learn more about working with Kafka, see the following links: