我正在使用Kafka版本0.11.0.0并尝试通过从avro文件加载数据来创建输入流。但它在实例化Producer时失败,但有例外:
[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
我正在关注我的工作链接:Confluent kafka stream example
实例化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);
答案 0 :(得分:0)
如异常所述,您会错过com.fasterxml.jackson.core.JsonProcessingException
类
您是否克隆了存储库,或者您只是复制粘贴代码?你需要一个正确的.pom
,就像这个:
https://github.com/confluentinc/examples/blob/3.3.0-post/kafka-streams/pom.xml
其中包括所有正确的依赖,包括杰克逊。
我建议克隆存储库(至少从这里开始的所有内容:https://github.com/confluentinc/examples/tree/3.3.0-post/kafka-streams)并遵循README中所述的命令和要求开始。