Bird
0
0

Which of the following code snippets correctly schedules this punctuator and ensures it triggers based on wall-clock time?

hard📝 Application Q15 of 15
Kafka - Advanced Stream Processing
You want to emit aggregated results every 30 seconds using a punctuator in Kafka Streams. Which of the following code snippets correctly schedules this punctuator and ensures it triggers based on wall-clock time?
Acontext.schedule(30, PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults())
Bcontext.schedule(Duration.ofSeconds(30), PunctuationType.STREAM_TIME, timestamp -> emitResults())
Ccontext.schedule(Duration.ofSeconds(30), PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults())
Dcontext.schedule(Duration.ofMinutes(1), PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults())
Step-by-Step Solution
Solution:
  1. Step 1: Determine the correct interval and time type

    The requirement is every 30 seconds and based on wall-clock time.
  2. Step 2: Match the correct schedule call

    context.schedule(Duration.ofSeconds(30), PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults()) uses Duration.ofSeconds(30) and PunctuationType.WALL_CLOCK_TIME, which is correct.
  3. Step 3: Check other options for errors

    context.schedule(Duration.ofSeconds(30), PunctuationType.STREAM_TIME, timestamp -> emitResults()) uses STREAM_TIME, not wall-clock; C uses int instead of Duration; D uses 1 minute instead of 30 seconds.
  4. Final Answer:

    context.schedule(Duration.ofSeconds(30), PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults()) -> Option C
  5. Quick Check:

    Wall-clock 30s interval = context.schedule(Duration.ofSeconds(30), PunctuationType.WALL_CLOCK_TIME, timestamp -> emitResults()) [OK]
Quick Trick: Use Duration.ofSeconds(30) with WALL_CLOCK_TIME for 30-second triggers [OK]
Common Mistakes:
MISTAKES
  • Using STREAM_TIME instead of WALL_CLOCK_TIME
  • Passing raw integers instead of Duration
  • Setting wrong time interval

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes