Kafka - Topics and PartitionsWhich of the following is the correct way to specify a key when producing a Kafka message in Java?Aproducer.send(new ProducerRecord<>(topic, key, value));Bproducer.send(new ProducerRecord<>(topic, value));Cproducer.send(new ProducerRecord<>(key, topic, value));Dproducer.send(new ProducerRecord<>(value, key));Check Answer
Step-by-Step SolutionSolution:Step 1: Recall ProducerRecord constructorThe correct constructor is ProducerRecord(topic, key, value).Step 2: Match options to constructorproducer.send(new ProducerRecord<>(topic, key, value)); matches the correct order: topic, key, value.Final Answer:producer.send(new ProducerRecord<>(topic, key, value)); -> Option AQuick Check:Correct ProducerRecord syntax = C [OK]Quick Trick: Topic first, then key, then value in ProducerRecord [OK]Common Mistakes:Swapping key and value positionsOmitting the key when neededPassing parameters in wrong order
Master "Topics and Partitions" in Kafka9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kafka Quizzes Consumers - Deserialization - Quiz 14medium Consumers - Offset management - Quiz 10hard Kafka Basics and Event Streaming - Kafka installation and setup - Quiz 15hard Kafka Cluster Architecture - Replication factor - Quiz 4medium Kafka Cluster Architecture - Broker configuration basics - Quiz 6medium Kafka Cluster Architecture - Broker configuration basics - Quiz 13medium Kafka Cluster Architecture - ZooKeeper role (and KRaft replacement) - Quiz 9hard Producers - Partitioner behavior - Quiz 15hard Producers - Message key and value - Quiz 2easy Topics and Partitions - Partition key and routing - Quiz 7medium