Why serialize/deserialize key and value in Apache Kafka?
configs.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
configs.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
Is there any benefit from using it?
Serialization
Serialization refers to the translation of java object state into bytes to send it over the network or store it in the hard disk.
Why we need Serialization?
We need serialization because the hard disk or network infrastructure is hardware component and we cannot send java objects because it understands just bytes and not java objects.
The same behavior is required in the Kafka also.so serialization/deserialization is required in Kafka.
Kafka provides some primitive serializers: for example, IntegerSerializer, ByteArraySerializer, StringSerializer
. On the consumer side, similar Deserializers
convert byte arrays to an object the application can deal with.
Avro is a popular serialization/deserialization framework for Kafka key/value