Java 获取相关id为92的元数据时出错:{myTest=UNKNOWN\u TOPIC\u或\u PARTITION}

Java 获取相关id为92的元数据时出错:{myTest=UNKNOWN\u TOPIC\u或\u PARTITION},java,apache-kafka,kafka-producer-api,Java,Apache Kafka,Kafka Producer Api,我创建了一个示例应用程序来检查我的生产者代码。当我在没有分区键的情况下发送数据时,我的应用程序运行良好。但是,在为数据分区指定密钥时,我得到了一个错误: [kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Error while fetching metadata with correlation id 3

我创建了一个示例应用程序来检查我的生产者代码。当我在没有分区键的情况下发送数据时,我的应用程序运行良好。但是,在为数据分区指定密钥时,我得到了一个错误:

[kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Error while fetching metadata with correlation id 37 : {myTest=UNKNOWN_TOPIC_OR_PARTITION}
[kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Error while fetching metadata with correlation id 38 : {myTest=UNKNOWN_TOPIC_OR_PARTITION}
[kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient - [Producer clientId=producer-1] Error while fetching metadata with correlation id 39 : {myTest=UNKNOWN_TOPIC_OR_PARTITION}
对于消费者和生产者。我在互联网上搜索了很多,他们建议验证kafka.acl设置。我正在HDInsight上使用卡夫卡,我不知道如何验证它并解决此问题

我的群集具有以下配置:

  • 头部节点:2
  • 工作节点:4
  • 动物园管理员:3
  • 我的制作人代码:

    public static void produce(String brokers, String topicName) throws IOException{
    
        // Set properties used to configure the producer
        Properties properties = new Properties();
          // Set the brokers (bootstrap servers)
        properties.setProperty("bootstrap.servers", brokers);
        properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
      properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    
        // specify the protocol for Domain Joined clusters
    
        //To create an Idempotent Producer
        properties.setProperty(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true");
        properties.setProperty(ProducerConfig.ACKS_CONFIG, "all");
        properties.setProperty(ProducerConfig.RETRIES_CONFIG, Integer.toString(Integer.MAX_VALUE));
        properties.setProperty(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "test-transactional-id"); 
        KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
        producer.initTransactions();
        // So we can generate random sentences
        Random random = new Random();
        String[] sentences = new String[] {
                "the cow jumped over the moon",
                "an apple a day keeps the doctor away",
                "four score and seven years ago",
                "snow white and the seven dwarfs",
                "i am at two with nature",
             };
    
    
        for(String sentence: sentences){
            // Send the sentence to the test topic
            try
            {
                String key=sentence.substring(0,2);
                producer.beginTransaction();
                producer.send(new ProducerRecord<String, String>(topicName,key,sentence)).get();
            }
            catch (Exception ex)
            {
              System.out.print(ex.getMessage());
                throw new IOException(ex.toString());
            }
            producer.commitTransaction();
        }
    }
    
    publicstaticvoidproduct(字符串代理、字符串topicName)抛出IOException{
    //设置用于配置生产者的属性
    属性=新属性();
    //设置代理(引导服务器)
    setProperty(“bootstrap.servers”,brokers);
    properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,StringSerializer.CLASS.getName());
    properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.CLASS.getName());
    //指定加入域的群集的协议
    //创建幂等生产者的步骤
    properties.setProperty(ProducerConfig.ENABLE_幂等性_CONFIG,“true”);
    properties.setProperty(ProducerConfig.ACKS_CONFIG,“all”);
    properties.setProperty(ProducerConfig.RETRIES_CONFIG,Integer.toString(Integer.MAX_VALUE));
    properties.setProperty(ProducerConfig.TRANSACTIONAL_ID_CONFIG,“测试事务ID”);
    卡夫卡制作人=新卡夫卡制作人(属性);
    producer.initTransactions();
    //所以我们可以生成随机的句子
    随机=新随机();
    字符串[]句子=新字符串[]{
    “奶牛跳过了月亮”,
    “一天一苹果,医生远离我”,
    “八十七年前”,
    “白雪公主和七个小矮人”,
    “我与大自然同在”,
    };
    for(字符串句子:句子){
    //将句子发送到测试主题
    尝试
    {
    字符串键=句子。子字符串(0,2);
    producer.beginTransaction();
    producer.send(新ProducerRecord(主题名、键、句子)).get();
    }
    捕获(例外情况除外)
    {
    System.out.print(例如getMessage());
    抛出新IOException(例如toString());
    }
    producer.commitTransaction();
    }
    }
    

    另外,我的主题由3个复制因子为3的分区组成。错误明确指出您要生成的主题(或分区)不存在

    最后,您需要描述主题(通过CLI
    kafka topics--descripe--topic
    或其他方式)来验证这是否正确

    卡夫卡关于HDInsight,我不知道如何验证它并解决这个问题


    ACL只有在安装了集群的情况下才会设置,但我相信您仍然可以通过
    zookeper shell
    或SSHing将ACL列出到Hadoop主机中

    我使复制因子小于分区的数量,这对我来说很有效。对我来说这听起来很奇怪,但是是的,它在它之后开始工作。

    我已经确保我的主题存在,而且当我在没有分区键的情况下发送时,代码运行得非常好。为什么在添加分区键时显示错误?不确定“分区键”是什么意思。它将是“记录键”,即使您没有实际设置一个,它仍然作为
    null
    发送。你用的是什么分区器?