I have two Kafka topics in my consumer application. How can I configure one topic to use StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer) and other one to use KafkaAvroDeserializer (io.confluent.kafka.serializers.KafkaAvroDeserializer)?
Asked
Active
Viewed 38 times
1
-
1Does this answer your question? [Using multiple deserializers for a kafka consumer](https://stackoverflow.com/questions/40218789/using-multiple-deserializers-for-a-kafka-consumer) – hermit Aug 11 '23 at 11:56
-
2The best and simplest way to achieve this is to configure and use two consumers. – Mar-Z Aug 11 '23 at 12:24
-
What have you tried so far? Deserializers are associated with consumers, not topics. So create two of them – OneCricketeer Aug 11 '23 at 12:54
-
Spring provides a `DelegatingByTopicDeserializer`. – Gary Russell Aug 23 '23 at 19:51
1 Answers
1
Use the DelegatingByTopicDeserializer
.
https://docs.spring.io/spring-kafka/docs/current/reference/html/#by-topic
Starting with version 2.8, the
DelegatingByTopicSerializer
andDelegatingByTopicDeserializer
allow selection of a serializer/deserializer based on the topic name. RegexPattern
s are used to lookup the instance to use.

Gary Russell
- 166,535
- 14
- 146
- 179