Duration: 40 mins
So far every exercise has used StringSerializer/StringDeserializer.
Real applications usually send structured data.
Define a case class:
case class Order(orderId: String, customerId: String, amount: BigDecimal)
Serializer[Order] and a matching
Deserializer[Order]:
upickle or
circe), serialize to/from Array[Byte] via UTF-8 stringsorderId|customerId|amount) works fine
for the exercise — the point is the Serializer/Deserializer
wiring, not the encoding itselfWire your Serializer/Deserializer classes into producer/consumer
configs via VALUE_SERIALIZER_CLASS_CONFIG /
VALUE_DESERIALIZER_CLASS_CONFIG (keep String for the key)
Update OrderProducerApp to send real Order values and
OrderConsumerApp to print the deserialized Order
Break it on purpose: publish one malformed record with the plain
kafka-console-producer (so it doesn’t match your encoding), then
run the consumer and observe what happens to a Deserializer that
throws — the consumer’s poll() call fails and, without handling,
the app gets stuck unable to progress past that offset
Fix it: wrap the decode step so a bad record is logged and skipped instead of crashing the consumer loop