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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -