ERROR org.apache.kafka.common.utils.KafkaThread – Uncaught exception in thread 'kafka-producer-network-thread

huangapple go评论66阅读模式
英文:

ERROR org.apache.kafka.common.utils.KafkaThread - Uncaught exception in thread 'kafka-producer-network-thread

问题

运行时出错如下:

[kafka-producer-network-thread | producer-1] ERROR org.apache.kafka.common.utils.KafkaThread - Uncaught exception in thread 'kafka-producer-network-thread | producer-1':
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode
    at org.apache.kafka.common.requests.ApiVersionsRequest$Builder.<clinit>(ApiVersionsRequest.java:36)
    at org.apache.kafka.clients.NetworkClient.handleConnections(NetworkClient.java:910)
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:555)
    at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:325)
    at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:240)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonNode
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

你的程序运行过程中出现了以下错误:

  1. Uncaught exception in thread 'kafka-producer-network-thread | producer-1',意味着一个线程发生了未捕获的异常。
  2. 错误信息中提到了 java.lang.NoClassDefFoundError,这表示找不到某个类的定义。
  3. 具体的缺失类是 com.fasterxml.jackson.databind.JsonNode,这是 Jackson 数据绑定库中的一个类。
  4. 错误堆栈显示了 Kafka 代码中的一些调用,最终导致了该缺失类的异常。

解决这个问题的方法是确保你的项目中正确地包含了所需的依赖。在你的 pom.xml 文件中,已经有了 Kafka 相关的依赖,但可能还需要包含 Jackson 数据绑定库的依赖。你可以尝试添加以下依赖来解决这个问题:

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.5</version> <!-- 选择一个合适的版本 -->
</dependency>

将上述依赖添加到你的 pom.xml 文件中,然后重新构建你的项目,看看是否解决了错误。如果仍然存在问题,你可能还需要检查一下其他依赖项是否正确,并确保它们的版本兼容性。

英文:

i am trying to create producer and send some data to it from intellij idea but while running this program i got ERROR like ERROR org.apache.kafka.common.utils.KafkaThread - Uncaught exception in thread &#39;kafka-producer-network-thread

i have written code for this program is like

package Kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class First_Producer {
    public static void main(String[] args) {


        String bootstrapserver = &quot;127.0.0.1:9092&quot;;

        //create producer properties
        Properties properties = new Properties();
        properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,bootstrapserver);
        properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());

        //create the producer
        KafkaProducer&lt;String,String&gt; producer= new KafkaProducer&lt;String,String&gt;(properties);

        //create a producer record
        ProducerRecord&lt;String, String&gt;  record = new ProducerRecord&lt;String,String&gt;(&quot;first_topic&quot;,&quot;hello_world&quot;);

        //send data
        producer.send(record);
        producer.flush();
        producer.close();
    }
}

pom.xml file

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;org.example&lt;/groupId&gt;
    &lt;artifactId&gt;KafkaProject&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

    &lt;dependencies&gt;
        &lt;!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.kafka&lt;/groupId&gt;
            &lt;artifactId&gt;kafka-clients&lt;/artifactId&gt;
            &lt;version&gt;2.6.0&lt;/version&gt;
        &lt;/dependency&gt;


        &lt;!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-simple&lt;/artifactId&gt;
            &lt;version&gt;1.7.30&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql-kafka-0-10 --&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.spark&lt;/groupId&gt;
            &lt;artifactId&gt;spark-sql-kafka-0-10_2.12&lt;/artifactId&gt;
            &lt;version&gt;3.0.0-preview&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/project&gt;

While running got error

     C:\Java\jdk1.8.0_161\bin\java.exe &quot;-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.4\lib\idea_rt.jar=7640:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.4\bin&quot; -Dfile.encoding=UTF-8 -classpath C:\Java\jdk1.8.0_161\jre\lib\charsets.jar;C:\Java\jdk1.8.0_161\jre\lib\deploy.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\access-bridge-64.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\cldrdata.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\dnsns.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\jaccess.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\jfxrt.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\localedata.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\nashorn.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\sunec.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\sunjce_provider.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\sunmscapi.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\sunpkcs11.jar;C:\Java\jdk1.8.0_161\jre\lib\ext\zipfs.jar;C:\Java\jdk1.8.0_161\jre\lib\javaws.jar;C:\Java\jdk1.8.0_161\jre\lib\jce.jar;C:\Java\jdk1.8.0_161\jre\lib\jfr.jar;C:\Java\jdk1.8.0_161\jre\lib\jfxswt.jar;C:\Java\jdk1.8.0_161\jre\lib\jsse.jar;C:\Java\jdk1.8.0_161\jre\lib\management-agent.jar;C:\Java\jdk1.8.0_161\jre\lib\plugin.jar;C:\Java\jdk1.8.0_161\jre\lib\resources.jar;C:\Java\jdk1.8.0_161\jre\lib\rt.jar;D:\KafkaProject\target\classes;D:\KafkaProject\slf4j-simple-1.7.30.jar;C:\Users\vishal\.m2\repository\org\apache\kafka\kafka-clients.6.0\kafka-clients-2.6.0.jar;C:\Users\vishal\.m2\repository\com\github\luben\zstd-jni.4.4-7\zstd-jni-1.4.4-7.jar;C:\Users\vishal\.m2\repository\org\lz4\lz4-java.7.1\lz4-java-1.7.1.jar;C:\Users\vishal\.m2\repository\org\xerial\snappy\snappy-java.1.7.3\snappy-java-1.1.7.3.jar;C:\Users\vishal\.m2\repository\org\slf4j\slf4j-api.7.30\slf4j-api-1.7.30.jar;C:\Users\vishal\.m2\repository\org\slf4j\slf4j-simple.7.30\slf4j-simple-1.7.30.jar Kafka.First_Producer
        SLF4J: Class path contains multiple SLF4J bindings.
        SLF4J: Found binding in [jar:file:/D:/KafkaProject/slf4j-simple-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
        SLF4J: Found binding in [jar:file:/C:/Users/vishal/.m2/repository/org/slf4j/slf4j-simple/1.7.30/slf4j-simple-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
        SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
        SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
        [main] INFO org.apache.kafka.clients.producer.ProducerConfig - ProducerConfig values: 
        	acks = 1
        	batch.size = 16384
        	bootstrap.servers = [127.0.0.1:9092]
        	buffer.memory = 33554432
        	client.dns.lookup = use_all_dns_ips
        	client.id = producer-1
        	compression.type = none
        	connections.max.idle.ms = 540000
        	delivery.timeout.ms = 120000
        	enable.idempotence = false
        	interceptor.classes = []
        	internal.auto.downgrade.txn.commit = false
        	key.serializer = class org.apache.kafka.common.serialization.StringSerializer
        	linger.ms = 0
        	max.block.ms = 60000
        	max.in.flight.requests.per.connection = 5
        	max.request.size = 1048576
        	metadata.max.age.ms = 300000
        	metadata.max.idle.ms = 300000
        	metric.reporters = []
        	metrics.num.samples = 2
        	metrics.recording.level = INFO
        	metrics.sample.window.ms = 30000
        	partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
        	receive.buffer.bytes = 32768
        	reconnect.backoff.max.ms = 1000
        	reconnect.backoff.ms = 50
        	request.timeout.ms = 30000
        	retries = 2147483647
        	retry.backoff.ms = 100
        	sasl.client.callback.handler.class = null
        	sasl.jaas.config = null
        	sasl.kerberos.kinit.cmd = /usr/bin/kinit
        	sasl.kerberos.min.time.before.relogin = 60000
        	sasl.kerberos.service.name = null
        	sasl.kerberos.ticket.renew.jitter = 0.05
        	sasl.kerberos.ticket.renew.window.factor = 0.8
        	sasl.login.callback.handler.class = null
        	sasl.login.class = null
        	sasl.login.refresh.buffer.seconds = 300
        	sasl.login.refresh.min.period.seconds = 60
        	sasl.login.refresh.window.factor = 0.8
        	sasl.login.refresh.window.jitter = 0.05
        	sasl.mechanism = GSSAPI
        	security.protocol = PLAINTEXT
        	security.providers = null
        	send.buffer.bytes = 131072
        	ssl.cipher.suites = null
        	ssl.enabled.protocols = [TLSv1.2]
        	ssl.endpoint.identification.algorithm = https
        	ssl.engine.factory.class = null
        	ssl.key.password = null
        	ssl.keymanager.algorithm = SunX509
        	ssl.keystore.location = null
        	ssl.keystore.password = null
        	ssl.keystore.type = JKS
        	ssl.protocol = TLSv1.2
        	ssl.provider = null
        	ssl.secure.random.implementation = null
        	ssl.trustmanager.algorithm = PKIX
        	ssl.truststore.location = null
        	ssl.truststore.password = null
        	ssl.truststore.type = JKS
        	transaction.timeout.ms = 60000
        	transactional.id = null
        	value.serializer = class org.apache.kafka.common.serialization.StringSerializer
        
        [main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.6.0
        [main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 62abe01bee039651
        [main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka startTimeMs: 1600385581070
        [kafka-producer-network-thread | producer-1] ERROR org.apache.kafka.common.utils.KafkaThread - Uncaught exception in thread &#39;kafka-producer-network-thread | producer-1&#39;:
        java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode
        	at org.apache.kafka.common.requests.ApiVersionsRequest$Builder.&lt;clinit&gt;(ApiVersionsRequest.java:36)
        	at org.apache.kafka.clients.NetworkClient.handleConnections(NetworkClient.java:910)
        	at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:555)
        	at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:325)
        	at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:240)
        	at java.lang.Thread.run(Thread.java:748)
        Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonNode
        	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        	... 6 more
        [main] INFO org.apache.kafka.clients.producer.KafkaProducer - [Producer clientId=producer-1] Closing the Kafka producer with timeoutMillis = 9223372036854775807 ms.
        
        Process finished with exit code 0

So, this all is my code and i am trying to create a kafka producer but i am getting error as above. so please anyone can assist me to resolve this problem

答案1

得分: 22

我遇到了同样的问题,通过添加以下依赖项,问题得到了解决。

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.10.3</version>
</dependency>
英文:

I was facing the same issue, by adding the below dependencies , the issue got resolved.

&lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
    &lt;version&gt;2.10.3&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年9月18日 07:58:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63947560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定