import org.apache.kafka.clients.producer.*; import java.util.Properties; public class KafkaProducerExample { public static void main(String[] args) { // Configure Kafka properties using Properties class Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); // Create a KafkaProducer instance with the configured properties KafkaProducer<String, String> producer = new KafkaProducer<>(props); // ... rest of your producer code ... // Close the producer when done producer.close(); } }