kafka 0.10.2 消息生产者

package cn.xiaojf.kafka.producer;

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; /**
* Created by 肖建锋 on 2017/3/22.
*/
public class MsgProducer2 {
public static void main(String[] args) {
Properties props = new Properties();
props.put("bootstrap.servers", "192.168.59.130:9092,192.168.59.131:9092,192.168.59.132:9092");
props.put("acks", "all");
props.put("retries ", 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(props);
for(int i = 0; i < 100; i++)
producer.send(new ProducerRecord<String, String>("my-replicated-topic", Integer.toString(i), Integer.toString(i)));
producer.close();
}
}
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.10.2.0</version>
</dependency>
上一篇:用label实现自适应宽度的方法


下一篇:Java中对象并不是都在堆上分配内存的