rk (1) [Avatar] Offline
#1
I created topic - 'some-topic' but when I try to run the code provided in the example it comes back with an error

Exception in thread "main" org.apache.kafka.common.errors.SerializationException: Can't convert key of class bbejeck.model.PurchaseKey to class org.apache.kafka.common.serialization.StringSerializer specified in key.serializer
Caused by: java.lang.ClassCastException: bbejeck.model.PurchaseKey cannot be cast to java.lang.String

Do I need to use a different serializer as key is of type bbejeck.model.PurchaseKey?
If so how do I write my own serializer?
Bill Bejeck (41) [Avatar] Offline
#2
Hi rk,

In Kafka Streams whenever you use a key or value of a type different from what the default serdes expect, you need to provide a custom one when consuming from a topic, writing to a topic or when using state stores.

The bbejeck.chapter_3.ZMartKafkaStreamsApp is an excellent example of providing a custom serde, although in this instance it's for a value object, the principle is the same.

I included the PurchaseKey object as an example of creating a custom key, but I never added a Serde for it in any of the sample code, which is an oversight on my part.

I'll get the serde added to the source code, but in the meantime, if you follow the pattern of Serde creation in the bbejeck.util.serde.StreamsSerde class, you should be able to create one quickly.

HTH

Cheers,
Bill
Bill Bejeck (41) [Avatar] Offline
#3
Just to follow up, I've added a PurchaseKey Serde to the source code, so when the book comes out it will be there for you to use.

Thanks,
Bill