import org.apache.kafka.clients.producer.ProducerConfig; import java.util.Properties; public class KafkaProducerCommon { public static final String STRING_SERIALIZER = "org.apache.kafka.common.serialization.StringSerializer"; static void configure(Properties props) { // We use "put" since there are strings. Otherwise, use setProperty. // These are the 3 required properties. // 1. Cluster membership: partition leaders, etc props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KafkaCommon.BROKERS); // 2. How keys and values are serialized. props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, STRING_SERIALIZER); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, STRING_SERIALIZER); } }