Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.IllegalStateException:此使用者已关闭_Java_Apache Kafka_Kafka Consumer Api - Fatal编程技术网

java.lang.IllegalStateException:此使用者已关闭

java.lang.IllegalStateException:此使用者已关闭,java,apache-kafka,kafka-consumer-api,Java,Apache Kafka,Kafka Consumer Api,使用此配置设置kafka consumer kafkaconfig: acks: 1 autoCommit: true bootstrapServers: example.com:9092 topic: item groupId: EWok-group keyDeserializer: org.apache.kafka.common.serialization.StringDeserializer valueDeserializer: org.apache.kafka

使用此配置设置kafka consumer

kafkaconfig:
  acks: 1
  autoCommit: true
  bootstrapServers: example.com:9092
  topic: item
  groupId: EWok-group
  keyDeserializer: org.apache.kafka.common.serialization.StringDeserializer
  valueDeserializer: org.apache.kafka.common.serialization.StringDeserializer
  maxPollRecords: 1
  pollMillisTime: 15
  retries: 5
  heartBeatInterval: 300
  sessionTimeout: 100000
  maxPollInterval: 30000
代码

卡夫卡版本:Kafka-clients-2.0.1

您能建议任何一个Kafka消费的配置是什么样子的吗?

我已经将System.exit(0)放在源代码中的其他位置。这就是为什么消费者已经离开组并标记为关闭的原因


我已从源代码中删除System.exit(0)。现在它工作正常。

这是否回答了您的问题?这完全类似于重复到标记的问题这不是重复的问题。我没有在while循环中关闭消费者,但我仅在异常将引发时关闭消费者。为什么不将捕获放在循环之外,然后关闭消费者@用户6903099
 while (true) {
            try {
                ConsumerRecords<String, String> consumerRecords = eWokIntegrationConsumer.poll(Duration.of(kafkaCommConfig.getPollMillisTime(), ChronoUnit.SECONDS));
                if (!consumerRecords.isEmpty()) {
                    LOG.info("Consumed Record Count: {}", consumerRecords.count());
                    consumerRecords.forEach(record -> {
                        System.out.printf("offset = %d, key = %s, value = %s\n", record.offset(), record.key(), record.value());
                        eWokMessageProcessor.onMessage(record.value());
                        eWokIntegrationConsumer.commitSync();
                    });
                } else {
                    LOG.info("Polling returned without any records.");
                }
            } catch (Exception exception) {
                LOG.error("Consumer was interrupted. But still continue to poll. Exception:", exception);
                eWokIntegrationConsumer.close();
            }
        }
java.lang.IllegalStateException: This consumer has already been closed.
    at org.apache.kafka.clients.consumer.KafkaConsumer.acquireAndEnsureOpen(KafkaConsumer.java:2202)
    at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1332)
    at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1298)