'Failed to construct kafka producer
I'm using Kafka version 0.11.0.0 and trying to create an input stream by loading data from avro file.But it fails in instantiating the Producer with the exception:
[main] INFO org.apache.kafka.clients.producer.KafkaProducer - Closing the Kafka producer with timeoutMillis = 0 ms.
Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka producer
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:415)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:287)
at wordcount.PayloadProducer.produceInputs(PayloadProducer.java:42)
at wordcount.PayloadProducer.main(PayloadProducer.java:24)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.<init>(CachedSchemaRegistryClient.java:47)
at io.confluent.kafka.serializers.AbstractKafkaAvroSerDe.configureClientProperties(AbstractKafkaAvroSerDe.java:73)
at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.configure(AbstractKafkaAvroSerializer.java:42)
at io.confluent.kafka.serializers.KafkaAvroSerializer.configure(KafkaAvroSerializer.java:48)
at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.configure(ExtendedSerializer.java:60)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:336)
... 3 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
I'm following this link for my work: Confluent kafka stream example
Code for instantiating Producer:
final Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
io.confluent.kafka.serializers.KafkaAvroSerializer.class);
props.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl);
GenericRecordBuilder pageViewBuilder = new GenericRecordBuilder(loadSchema("payload.avsc"));
KafkaProducer<String, GenericRecord> producer = new KafkaProducer<>(props);
Solution 1:[1]
As stated by exception, you miss com.fasterxml.jackson.core.JsonProcessingException class
Did you clone the repository, or did you just copy paste the code? You need a correct .pom, like this one:
https://github.com/confluentinc/examples/blob/3.3.0-post/kafka-streams/pom.xml
Which include all correct dependancies, including jackson.
I would advise cloning the repository (at least everything from here: https://github.com/confluentinc/examples/tree/3.3.0-post/kafka-streams) and follow commands and requirements stated in README to begin with.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Treziac |
