The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

rk (1) [Avatar] Offline
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 (47) [Avatar] Offline
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.


Bill Bejeck (47) [Avatar] Offline
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.