How to send json data to kafka using Java
我想大声告诉你
我想大声告诉你 2017-05-17 10:05:08
0
1
1221

On the Internet, I only see some news about Java producing STRING type.
According to Java's producer class, you can customize the type of message sent, such as producer.send(new KeyedMessage<String, HashMap<String, String>>(topic,message);
But it runs like this An error will be reported. The error is as follows. Please give an expert's answer:
Exception in thread "Thread-4" java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String

at kafka.serializer.StringEncoder.toBytes(Encoder.scala:46)
at kafka.producer.async.DefaultEventHandler$$anonfun$serialize.apply(DefaultEventHandler.scala:130)
at kafka.producer.async.DefaultEventHandler$$anonfun$serialize.apply(DefaultEventHandler.scala:125)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:34)
at kafka.producer.async.DefaultEventHandler.serialize(DefaultEventHandler.scala:125)
at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:52)
at kafka.producer.Producer.send(Producer.scala:77)
at kafka.javaapi.producer.Producer.send(Producer.scala:33)
at com.Model.Producer.kafkaProducer.run(kafkaProducer.java:35)
我想大声告诉你
我想大声告诉你

reply all(1)
过去多啦不再A梦

Document, just serialize it into String

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template