Bird
0
0

Consider the following Kafka Streams code snippet. What will be printed if the key "order789" exists with value "completed" in the orderStore?

medium📝 Predict Output Q4 of 15
Kafka - Advanced Stream Processing

Consider the following Kafka Streams code snippet. What will be printed if the key "order789" exists with value "completed" in the orderStore?

ReadOnlyKeyValueStore<String, String> store = streams.store("orderStore", QueryableStoreTypes.keyValueStore());
String status = store.get("order789");
System.out.println(status);
Anull
B"order789"
C"completed"
DException thrown
Step-by-Step Solution
Solution:
  1. Step 1: Retrieve the store

    The store is correctly retrieved as a read-only key-value store.
  2. Step 2: Get the value for the key

    Calling store.get("order789") returns the value associated with the key if it exists.
  3. Step 3: Print the value

    Since the key exists with value "completed", that value is printed.
  4. Final Answer:

    "completed" -> Option C
  5. Quick Check:

    Key exists, so value returned [OK]
Quick Trick: store.get(key) returns value or null if absent [OK]
Common Mistakes:
  • Assuming the key returns the key itself
  • Expecting null when key exists
  • Not handling exceptions for missing stores

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes