Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default serializer for kafka 0.8.2.0

Tags:

apache-kafka

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

like image 871
user3155931 Avatar asked Feb 27 '15 00:02

user3155931


People also ask

What is the default serializer for Kafka?

SerDes specified in the Streams configuration via StreamsConfig are used as the default in your Kafka Streams application.

What is Kafka serializer?

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.

What is key serializer and value serializer in Kafka?

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.


1 Answers

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");
like image 174
Superaghu Avatar answered Oct 12 '22 14:10

Superaghu