MAPREDUCE服务 MRS-Kafka应用开发规则:调用Kafka API(AdminZkClient.createTopic)创建Topic

时间:2024-05-28 14:22:56

调用Kafka API(AdminZkClient.createTopic)创建Topic

  • 对于Java开发语言,正确示例:
    import kafka.zk.AdminZkClient;
    import kafka.zk.KafkaZkClient;
    import kafka.admin.RackAwareMode;
    … 
    KafkaZkClient kafkaZkClient = KafkaZkClient.apply(zkUrl, JaasUtils.isZkSecurityEnabled(), zkSessionTimeoutMs, zkConnectionTimeoutMs, Int.MaxValue(), Time.SYSTEM, "", "", null);
    AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient);
    adminZkClient.createTopic(topic, partitions, replicas, new Properties(), RackAwareMode.Enforced$.MODULE$);
    …
  • 对于Scala开发语言,正确示例:
    import kafka.zk.AdminZkClient;
    import kafka.zk.KafkaZkClient;
    … 
    val kafkaZkClient: KafkaZkClient = KafkaZkClient.apply(zkUrl, JaasUtils.isZkSecurityEnabled(), zkSessionTimeoutMs, zkConnectionTimeoutMs, Int.MaxValue, Time.SYSTEM, "", "")
    val adminZkClient: AdminZkClient = new AdminZkClient(kafkaZkClient)
    adminZkClient.createTopic(topic, partitions, replicas)
support.huaweicloud.com/devg-rule-mrs/mrs_07_450030.html