简体   繁体   中英

How do I set the value de/serializer for a Kafka KeyValueStore?

I am storing the messages from a Kafka topic in a KeyValueStore so that I can query them later. I create a KTable as follows:

@StreamListener public void process(@Input("input") KTable<String,MyMessage> myMessages) {

I configured the consumer in my application.yml as follows:

UPDATED de/serializer package

spring.cloud.stream.kafka.streams.bindings.input: consumer: materializedAs: all-messages key-deserializer: org.apache.kafka.common.serialization.StringDeserializer value-deserializer: com.me.MyMessageDeserializer key-serializer: org.apache.kafka.common.serialization.StringSerializer value-serializer: com.me.MyMessageSerializer

However, when I read from the KeyValueStore the keys are returned correctly as Strings but the values returned are Byte arrays not MyMessage. For some reason my custom deserializer is not being used. I tried to deserialize the message myself, but my deserializer crashed with an exception. I put a breakpoint on my serializer and it is never called. It is clear to me that neither my serializer or deserializer are being used.

What configuration am I missing so that my custom value de/serializer will be used? Do the de/serializers need to be in a specific package to be found?

The wrong configuration keys were used in the application.yml. Instead of key-deserializer: it should be keySerde: and instead of value-deserializer: it should be valueSerde. Below is the correct configuration:

spring.cloud.stream.kafka.streams.bindings.input: consumer: materializedAs: all-messages keySerde: org.apache.kafka.common.serialization.Serdes$StringSerde valueSerde: com.me.MyMessageSerde producer: keySerde: org.apache.kafka.common.serialization.Serdes$StringSerde valueSerde: com.me.MyMessageSerde

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM