Skip to content

Instantly share code, notes, and snippets.

@pradp
Last active April 8, 2018 15:54
Show Gist options
  • Save pradp/469959bd8ed0b010bb3cdf1c75652b19 to your computer and use it in GitHub Desktop.
Save pradp/469959bd8ed0b010bb3cdf1c75652b19 to your computer and use it in GitHub Desktop.
public class SampleProducer {
public static void main(String[] args) {
Properties props = new Properties();
props.put("bootstrap.servers", "kafka-a.company.com:9092,kafka-b.company.com:9092,kafka-c.company.com:9092");
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL");
props.put("sasl.mechanism", "PLAIN");
//Few more props. Refer https://gist.github.com/pradp/a18312ab72e50117075131efc1a87629
Producer<String, String> producer = new KafkaProducer<String, String>(props);
Random rand = new Random();
for (int i = 0; i < 100; i++)
producer.send(new ProducerRecord<String, String>("sample-topic", Integer.toString(i), Integer
.toString(rand.nextInt())));
producer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment