Kafka Producer Consumer

org.apache.kafka.clients.producer.KafkaProducer

1 props.put("bootstrap.servers", "192.168.1.128:9092"); 2 props.put("acks", "all"); 3 props.put("retries", 0); 4 props.put("batch.size", 16384); 5 props.put("linger.ms", 1); 6 props.put("buffer.memory", 33554432); 7 props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); 8 props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); 9 10 Producer<String, String> producer = new KafkaProducer<String, String>(props); 11 for (int i = 0; i < 10; i++) { 12 producer.send(new ProducerRecord<String, String>("foo", Integer.toString(i), Integer.toString(i)), new Callback() { 13 @Override 14 public void onCompletion(RecordMetadata recordMetadata, Exception e) { 15 if (null != e) { 16 e.printStackTrace(); 17 }else { 18 System.out.println("callback: " + recordMetadata.topic() + " " + recordMetadata.offset()); 19 } 20 } 21 }); 22 } 23 producer.close();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wspdww.html