I am setting up Kafka producer using their new KafkaProducer API and getting following error
Exception in thread "main" org.apache.kafka.common.config.ConfigException: Missing required configuration "key.serializer" which has no default value.
at org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:124)
at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:48)
at org.apache.kafka.clients.producer.ProducerConfig.<init>(ProducerConfig.java:235)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:129)
at com.kafka.producer.App.KafkaProducer(App.java:43)
at com.kafka.producer.App.main(App.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
There seems to be no default serializer and the documentation at http://kafka.apache.org/documentation.html#newproducerconfigs and I do not see possible values.
This question is for Kafka 0.8.2.0 version
SerDes specified in the Streams configuration via StreamsConfig are used as the default in your Kafka Streams application.
Serialization is the process of converting objects into bytes. Deserialization is the inverse process — converting a stream of bytes into an object. In a nutshell, it transforms the content into readable and interpretable information.
The key. serializer and value. serializer instruct how to turn the key and value objects the user provides with their ProducerRecord into bytes. You can use the included ByteArraySerializer or StringSerializer for simple string or byte types.
The earlier versions of Kafka came with default serializer but that created lot of confusion.
With 0.8.2, you would need to pick a serializer yourself from StringSerializer or ByteArraySerializer that comes with API or build your own.
The API serializers can be found at StringSerializer: http://kafka.apache.org/082/javadoc/org/apache/kafka/common/serialization/StringSerializer.html ByteArraySerializer: http://kafka.apache.org/082/javadoc/org/apache/kafka/common/serialization/ByteArraySerializer.html
So, your solution would be to use one of the below options if you are looking to use default Serializers.
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
or
props.put("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With