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.>
If you call Serdes.serdeFrom(...)
you get a WrappedSerde
type back that is for internal usage (and WrappedSerde
does not have an non-argument constructor). There is currently no API you can call to get a custom Serde
. Instead, you need to implement you own Serde
class and wrap you serializer and deserializer "manually".
public class EventMessageSerde implements Serde {
final private JsonSerializer serializer;
final private JsonDeserializer deserializer;
@Override
public void configure(Map configs, boolean isKey) {
serializer.configure(configs, isKey);
deserializer.configure(configs, isKey);
}
@Override
public void close() {
serializer.close();
deserializer.close();
}
@Override
public Serializer serializer() {
return serializer;
}
@Override
public Deserializer deserializer() {
return deserializer;
}
}
In your Properties
you can set:
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, EventMessageSerde.class);