Bird
Raised Fist0

Identify the error in this Kafka consumer code snippet:

medium📝 Debug Q6 of Q15
Kafka - with Java/Python

Identify the error in this Kafka consumer code snippet:

Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "group1");
props.put("key.deserializer", "StringDeserializer");
props.put("value.deserializer", "StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
ADeserializer class names must be fully qualified with package names.
Bgroup.id cannot be set to 'group1'.
Cbootstrap.servers should be a list, not a string.
DKafkaConsumer constructor requires a second argument.
Step-by-Step Solution
Solution:
  1. Step 1: Check deserializer class names

    The deserializer class names must include the full package path, e.g., "org.apache.kafka.common.serialization.StringDeserializer".
  2. Step 2: Validate other properties

    group.id can be any string, bootstrap.servers accepts a comma-separated string, and KafkaConsumer constructor accepts a single Properties argument.
  3. Final Answer:

    Deserializer class names must be fully qualified with package names. -> Option A
  4. Quick Check:

    Deserializer names need full package = C [OK]
Quick Trick: Always use full package names for deserializers [OK]
Common Mistakes:
MISTAKES
  • Using short class names for deserializers
  • Misunderstanding group.id format
  • Expecting multiple constructor arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes