Bird
Raised Fist0

How can you programmatically produce messages to a compacted topic ensuring keys are used for compaction?

hard🚀 Application Q9 of Q15
Kafka - Monitoring and Operations
How can you programmatically produce messages to a compacted topic ensuring keys are used for compaction?
ASet cleanup.policy=compact in the producer config
BSend messages without keys to speed up compaction
CUse null keys to mark messages for compaction
DAlways set a non-null key when producing messages
Step-by-Step Solution
Solution:
  1. Step 1: Understand compaction key requirement

    Compaction works by key, so messages must have non-null keys to be compacted.
  2. Step 2: Evaluate options

    Sending messages without keys disables compaction, null keys are invalid, cleanup.policy is topic config, not producer.
  3. Final Answer:

    Always set a non-null key when producing messages -> Option D
  4. Quick Check:

    Non-null keys required for compaction [OK]
Quick Trick: Set non-null keys in messages to enable compaction [OK]
Common Mistakes:
MISTAKES
  • Sending messages without keys expecting compaction
  • Using null keys to trigger compaction
  • Trying to set cleanup.policy in producer config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes