KafkaProducerCommon.java 734 B

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