Created
April 7, 2018 13:56
-
-
Save pradp/a18312ab72e50117075131efc1a87629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.kafka.clients.CommonClientConfigs; | |
import org.apache.kafka.clients.producer.KafkaProducer; | |
import org.apache.kafka.clients.producer.Producer; | |
import org.apache.kafka.clients.producer.ProducerRecord; | |
import java.util.Properties; | |
import java.util.Random; | |
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"); | |
props.put("acks", "all"); | |
props.put("retries", 0); | |
props.put("batch.size", 16384); | |
props.put("linger.ms", 1); | |
props.put("buffer.memory", 33554432); | |
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); | |
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); | |
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>("cost-amend-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