老师为何结果我这个不对啊
来源:5-3 Producer异步阻塞发送演示

qq_慕莱坞4316410
2020-09-25
key-i:0 partition:0 offset:50
key-i:1 partition:0 offset:51
key-i:2 partition:0 offset:52
key-i:3 partition:0 offset:53
key-i:4 partition:0 offset:54
key-i:5 partition:0 offset:55
key-i:6 partition:0 offset:56
key-i:7 partition:0 offset:57
key-i:8 partition:0 offset:58
key-i:9 partition:0 offset:59
代码
public static void ProducerSyncSend() throws Exception{
Properties properties=new Properties();
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,“192.168.59.129:9092”);
properties.put(ProducerConfig.ACKS_CONFIG,“all”);
properties.put(ProducerConfig.RETRIES_CONFIG,“0”);
properties.put(ProducerConfig.BATCH_SIZE_CONFIG,“16384”);
properties.put(ProducerConfig.LINGER_MS_CONFIG,“1”);
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG,“33554432”);
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
Producer<String,String>producer=new KafkaProducer<>(properties);
for (int i=0;i<10;i++) {
String key="key-i:"+i;
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(topicName,"key-:"+key
+"value-:"+i);
Future<RecordMetadata>send=producer.send(producerRecord);
RecordMetadata metadata=send.get();
System.out.println(key+"\t partition:"+metadata.partition()+"\t offset:"+metadata.offset());
}
producer.close();
}
是哪里写错了啊
1回答
-
Allen
2020-09-25
正确的结果应该是什么
122020-09-27
相似问题