线程'kafka-producer-network-thread中未捕获的异常|生产者1

时间:2019-11-05 09:38:17

标签: java spring-boot apache-kafka spring-kafka

生成卡夫卡后,未捕获的异常发生在日志中。但是成功地生产了卡夫卡饲料。我想了解为什么出现此日志,其严重性以及如何解决。谢谢!

pom.xml中的Kafka依赖关系如下所示:

<dependency>
   <groupId>org.apache.kafka</groupId>
   <artifactId>kafka-streams</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.kafka</groupId>
    <artifactId>spring-kafka</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.0.0</version>
</dependency>

我的生产者配置如下:

@Bean
public ProducerFactory<String, Object> jsonProducerFactory() {
    Map<String, Object> configProps = new HashMap<>();
    configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootstrapServers);
    configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
    configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
    configProps.put(ProducerConfig.BATCH_SIZE_CONFIG, 500);
    configProps.put(ProducerConfig.LINGER_MS_CONFIG, 1000);
    configProps.put(ProducerConfig.RETRIES_CONFIG, 0);
    configProps.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 50000000);
    configProps.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, 5048576);
    return new DefaultKafkaProducerFactory<>(configProps);
}

@Bean
public KafkaTemplate<String, Object> jsonKkafkaTemplate() {
    return new KafkaTemplate<>(jsonProducerFactory());
}

我有此日志:

java.lang.NoSuchMethodError: org.apache.kafka.clients.producer.Producer.close(Ljava/time/Duration;)V
    at org.springframework.kafka.core.KafkaTemplate.closeProducer(KafkaTemplate.java:382) ~[spring-kafka-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.kafka.core.KafkaTemplate.lambda$buildCallback$4(KafkaTemplate.java:433) ~[spring-kafka-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.apache.kafka.clients.producer.KafkaProducer$InterceptorCallback.onCompletion(KafkaProducer.java:1235) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.ProducerBatch.completeFutureAndFireCallbacks(ProducerBatch.java:201) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.ProducerBatch.done(ProducerBatch.java:187) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.completeBatch(Sender.java:599) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.completeBatch(Sender.java:575) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.handleProduceResponse(Sender.java:485) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.access$100(Sender.java:74) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender$1.onComplete(Sender.java:700) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.ClientResponse.onComplete(ClientResponse.java:109) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.NetworkClient.completeResponses(NetworkClient.java:532) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:524) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239) ~[kafka-clients-2.0.0.jar:na]
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:163) ~[kafka-clients-2.0.0.jar:na]
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_121]

1 个答案:

答案 0 :(得分:1)

您使用的Kafka客户端库与Spring Kafka和Kafka Stream库不兼容。这是依赖性问题;您可以尝试从Kafka Clients依赖项中删除该版本,以加载默认的兼容版本,或者可以显式指定受支持的版本。

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version><Supported Version></version>
</dependency>