Consider the following Kafka Streams code snippet that uses a custom error handler. What will be printed when a deserialization error occurs?
StreamsBuilder builder = new StreamsBuilder(); builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String()) .withErrorHandler((context, exception) -> { System.out.println("Error in topic: " + context.topic()); return DeserializationHandlerResponse.CONTINUE; })) .to("output-topic"); KafkaStreams streams = new KafkaStreams(builder.build(), new Properties()); // Assume a deserialization error occurs on "input-topic"
Think about what the error handler prints and which topic it refers to.
The error handler prints the topic where the error happened, which is the input topic. It then returns CONTINUE, so the stream continues running.
Kafka Streams offers different error handling strategies. Which one will cause the application to stop processing when an error occurs?
Consider which strategy prioritizes safety by stopping on errors.
The 'fail fast' strategy stops the Kafka Streams application immediately when an error occurs to avoid inconsistent state.
Review the following Kafka Streams error handler setup. What is the error that will cause a runtime failure?
StreamsBuilder builder = new StreamsBuilder(); builder.stream("input-topic", Consumed.with(Serdes.String(), Serdes.String()) .withErrorHandler((context, exception) -> { System.out.println("Error in topic: " + context.topic()); return DeserializationHandlerResponse.FAIL; })) .to("output-topic"); KafkaStreams streams = new KafkaStreams(builder.build(), new Properties()); streams.start();
Think about what happens when FAIL is returned and how the stream lifecycle is managed.
Returning FAIL tells Kafka Streams to stop processing on error, but if the application does not close the stream properly, resources may leak.
Choose the code snippet that correctly sets a deserialization error handler in Kafka Streams.
Recall Java lambda syntax and method chaining style.
Option A uses correct Java lambda syntax and method chaining. Option A uses invalid syntax for Java. Option A misses a semicolon. Option A uses JavaScript arrow syntax, invalid in Java.
Assume a Kafka Streams application processes a batch of 3 messages, all corrupted causing deserialization errors. The error handler is set to CONTINUE after logging. How many times will the error handler be invoked?
Think about how Kafka Streams processes each message and triggers error handlers.
The error handler is invoked once per corrupted message, so for 3 corrupted messages, it is called 3 times.