Bird
0
0

What is wrong with the following Kafka Streams code snippet for accessing a state store?

medium📝 Debug Q6 of 15
Kafka - Advanced Stream Processing

What is wrong with the following Kafka Streams code snippet for accessing a state store?

ReadOnlyKeyValueStore<String, String> store = streams.store("metricsStore");
String metric = store.get("cpu");
AThe get() method cannot be used on ReadOnlyKeyValueStore
BThe store name "metricsStore" is invalid
CMissing the QueryableStoreTypes parameter in the store() method call
DThe variable 'metric' should be an integer, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check store() method signature

    The store() method requires two parameters: the store name and the store type.
  2. Step 2: Identify missing parameter

    The code omits the second parameter QueryableStoreTypes.keyValueStore(), which is mandatory.
  3. Final Answer:

    Missing the QueryableStoreTypes parameter in the store() method call -> Option C
  4. Quick Check:

    store() needs store type [OK]
Quick Trick: Always specify QueryableStoreTypes when calling store() [OK]
Common Mistakes:
MISTAKES
  • Calling store() with only the store name
  • Assuming get() is invalid on ReadOnlyKeyValueStore
  • Confusing variable types for store values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes