Bird
0
0

Identify the error in this Kafka Streams code snippet for exactly-once processing:

medium📝 Debug Q14 of 15
Kafka - Advanced Stream Processing
Identify the error in this Kafka Streams code snippet for exactly-once processing:
props.put("enable.idempotence", "true");
props.put("transactional.id", "txn-1");
KafkaProducer producer = new KafkaProducer(props);
producer.beginTransaction();
producer.send(record);
// Missing commit or abort here
producer.close();
AMissing commitTransaction or abortTransaction before close.
Benable.idempotence should be false for transactions.
Ctransactional.id must be unique per message.
DKafkaProducer cannot be closed after sending messages.
Step-by-Step Solution
Solution:
  1. Step 1: Review transaction lifecycle

    After beginTransaction and send, a commit or abort must finalize the transaction.
  2. Step 2: Identify missing step

    The code closes producer without committing or aborting, causing incomplete transaction.
  3. Final Answer:

    Missing commitTransaction or abortTransaction before close. -> Option A
  4. Quick Check:

    Transactions need commit or abort before close [OK]
Quick Trick: Always commit or abort before closing producer [OK]
Common Mistakes:
  • Thinking idempotence false is needed for transactions
  • Believing transactional.id changes per message
  • Assuming producer close auto-commits transactions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes