0
0
Kafkadevops~10 mins

Error handling in streams in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Kafka Streams builder.

Kafka
StreamsBuilder [1] = new StreamsBuilder();
Drag options to blanks, or click blank then click option'
AkafkaBuilder
BstreamBuilder
Cstream
Dbuilder
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not descriptive or confusing.
Forgetting to create the StreamsBuilder instance.
2fill in blank
medium

Complete the code to add a global error handler to the Kafka Streams configuration.

Kafka
props.put(StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG, [1].class);
Drag options to blanks, or click blank then click option'
ALogAndContinueExceptionHandler
BFailOnInvalidTimestampExceptionHandler
CLogAndFailExceptionHandler
DIgnoreExceptionHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using a handler that stops the stream on error.
Choosing a handler that ignores errors silently.
3fill in blank
hard

Fix the error in the code to handle deserialization exceptions by skipping bad records.

Kafka
builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String())
       .with[1](new LogAndContinueExceptionHandler()));
Drag options to blanks, or click blank then click option'
AerrorHandler
BdeserializationExceptionHandler
CdeserializationExceptionHandlerClass
DexceptionHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist.
Passing an instance instead of a class.
4fill in blank
hard

Fill both blanks to create a try-catch block that logs and skips processing on exceptions.

Kafka
try {
    processRecord(record);
} catch ([1] e) {
    logger.[2]("Error processing record, skipping", e);
}
Drag options to blanks, or click blank then click option'
AException
Berror
Cwarn
DThrowable
Attempts:
3 left
💡 Hint
Common Mistakes
Catching Throwable which is too broad.
Using logger.error which may stop processing.
5fill in blank
hard

Fill all three blanks to define a custom deserialization exception handler class.

Kafka
public class [1] implements DeserializationExceptionHandler {

    @Override
    public DeserializationHandlerResponse handle(Exception exception, ConsumerRecord<byte[], byte[]> record) {
        // Log the error
        logger.[2]("Deserialization error for record: " + record, exception);
        return DeserializationHandlerResponse.[3];
    }
}
Drag options to blanks, or click blank then click option'
ACustomDeserializationExceptionHandler
Bwarn
CCONTINUE
DhandleException
Attempts:
3 left
💡 Hint
Common Mistakes
Returning FAIL which stops the stream.
Using logger.error which is too severe here.