KafkaStreams serde exception

前端 未结 3 869
野性不改
野性不改 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:45

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

提交回复
热议问题