KafkaStreams serde exception

前端 未结 3 868
野性不改
野性不改 2021-01-06 03:51

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.

3条回答
  •  不知归路
    2021-01-06 04:39

    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);
    

提交回复
热议问题