Warm tip: This article is reproduced from stackoverflow.com, please click
apache-kafka java serialization deserialization kafka-serializer

What does configure function do in Kafka serializers / deserializers?

发布于 2020-03-27 15:39:27

I am looking into implementing custom Serializers / Deserializers for Kafka. To implement a Kafka custom Serializer / Deserializer, we have to implement org.apache.kafka.common.serialization.Serializer and org.apache.kafka.common.serialization.Deserializer respectively.

What I don't understand is the configure(Map configs, boolean key) method. What does it do? What should we pass into it? What is the purpose of this?

Most of the examples I came into, have not implemented anything inside the method. But I want to know what exactly this does. Not just ignore it.

Questioner
ThisaruG
Viewed
56
Fatema Sagar 2020-01-31 16:06

As you are trying to implement a custom serializer, the configure method will be used to configure the serializer at the start. If you want to read more about the configure method kindly go through this link: https://kafka.apache.org/20/javadoc/org/apache/kafka/common/serialization/Serializer.html

void configure​(java.util.Map configs, boolean isKey)

Configure this class.

Parameters: configs - configs in key/value pairs, isKey - whether is for key or value

Basically, the configure method accepts the Configurations Map as its first argument and second argument a boolean value, which sets true if it is for a Key or false if it is for value.