Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Kafka Streams builder.
Kafka
StreamsBuilder [1] = new StreamsBuilder(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not descriptive or confusing.
Forgetting to create the StreamsBuilder instance.
✗ Incorrect
The variable name for the StreamsBuilder instance is commonly 'builder'.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a handler that stops the stream on error.
Choosing a handler that ignores errors silently.
✗ Incorrect
LogAndContinueExceptionHandler logs errors and continues processing, useful for error handling.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist.
Passing an instance instead of a class.
✗ Incorrect
The correct method is 'withDeserializationExceptionHandler' to set the handler instance.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Catching Throwable which is too broad.
Using logger.error which may stop processing.
✗ Incorrect
Catch general Exception and log a warning to skip bad records.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning FAIL which stops the stream.
Using logger.error which is too severe here.
✗ Incorrect
The class name is custom, logs a warning, and returns CONTINUE to skip bad records.