Kafka - Topics and PartitionsWhich of the following is the correct way to specify a partition key when producing a Kafka message in Java?Aproducer.send(new ProducerRecord<>(topic, value));Bproducer.send(new ProducerRecord<>(value, key));Cproducer.send(new ProducerRecord<>(key, topic, value));Dproducer.send(new ProducerRecord<>(topic, key, value));Check Answer
Step-by-Step SolutionSolution:Step 1: Recall ProducerRecord constructorThe correct constructor order is (topic, key, value) to specify partition key.Step 2: Match options to constructorproducer.send(new ProducerRecord<>(topic, key, value)); matches this order exactly, others mix parameters incorrectly.Final Answer:producer.send(new ProducerRecord<>(topic, key, value)); -> Option DQuick Check:Topic, key, value order = B [OK]Quick Trick: Remember ProducerRecord(topic, key, value) order [OK]Common Mistakes:Swapping key and value positionsOmitting the key parameterPlacing key before topic incorrectly
Master "Topics and Partitions" in Kafka9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kafka Quizzes Consumer Groups - Cooperative vs eager rebalancing - Quiz 9hard Consumer Groups - Cooperative vs eager rebalancing - Quiz 6medium Consumers - Offset management - Quiz 13medium Consumers - Why consumers process messages - Quiz 13medium Kafka Basics and Event Streaming - Message broker architecture - Quiz 7medium Kafka Basics and Event Streaming - Event streaming concept - Quiz 6medium Kafka Cluster Architecture - ZooKeeper role (and KRaft replacement) - Quiz 11easy Producers - Acknowledgment modes (acks=0, 1, all) - Quiz 5medium Producers - Producer retries and idempotency - Quiz 2easy Topics and Partitions - Partition ordering guarantees - Quiz 14medium