Apache kafka sending java object failed -
i have object
hashmap message = new hashmap(); message.put("x", "xxxxx"); message.put("y", "yyyyy"); message.put("z", 100); producerrecord producerrecord = new producerrecord(topic, message); producer.send(producerrecord);
i getting
exception in thread "main" org.apache.kafka.common.errors.serializationexception: can't convert value of class java.util.hashmap class org.apache.kafka.common.serialization.stringserializer specified in value.serializer
you have provide kafka way how convert messages, in case hashmap
, binary form. kafka documentation:
the key.serializer , value.serializer instruct how turn key , value objects user provides producerrecord bytes. can use included bytearrayserializer or stringserializer simple string or byte types.
the example of usage:
properties props = new properties(); props.put("key.serializer", "yourimplementation"); props.put("value.serializer", "yourimplementation"); producer<string, hashmap> producer = new kafkaproducer<>(props);
Comments
Post a Comment