i am playing with Kafka and streams technology; i have created a custom serializer and deserializer for the KStream that i will use to receive messages from a given topic.>
Another way is using StreamsBuilder
instead of KStreamBuilder
. KStreamBuilder
is deprecated in 1.0.0. You can directly pass serde object using Consumed.with
while creating stream. You need not to create custom Serde
class in this scenario.
Serde messageSerde = Serdes.serdeFrom(serializer, deserializer);
StreamsBuilder builder = new StreamsBuilder();
KStream eventsStream = builder.stream(topic, Consumed.with(Serdes.String(), messageSerde));
You can keep StringSerde
in below code instead of using messageSerde.getClass()
which is failing because messageSerde
is just a WrappedSerde
that does not have non-argument constructor.
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, StringSerde.class.getName());