Bird
0
0

Consider the following Kafka Streams processor code snippet:

medium📝 Debug Q7 of 15
Kafka - Advanced Stream Processing
Consider the following Kafka Streams processor code snippet:
public void init(ProcessorContext context) {
  KeyValueStore store = context.getStateStore("myStore");
}
What is the main issue with this code?
AThe init method should not accept ProcessorContext as a parameter.
BThe state store name "myStore" must be registered before accessing it.
CThe returned object from getStateStore() must be cast to KeyValueStore<String, String>.
DState stores cannot be accessed inside the init method.
Step-by-Step Solution
Solution:
  1. Step 1: Understand getStateStore() return type

    The method context.getStateStore() returns a generic StateStore object.
  2. Step 2: Casting requirement

    To use it as a KeyValueStore, an explicit cast is required.
  3. Step 3: Evaluate options

    The returned object from getStateStore() must be cast to KeyValueStore. correctly identifies the missing cast. The state store name "myStore" must be registered before accessing it. is true but not the main issue here. Options C and D are incorrect.
  4. Final Answer:

    The returned object from getStateStore() must be cast to KeyValueStore<String, String>. -> Option C
  5. Quick Check:

    Cast getStateStore() result to specific store type [OK]
Quick Trick: Cast getStateStore() to correct store type [OK]
Common Mistakes:
  • Not casting the returned StateStore
  • Assuming state store is auto-typed
  • Trying to access store before registration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes