码迷,mamicode.com
首页 > 其他好文 > 详细

kafka 0.10.2 消息生产者

时间:2017-03-23 01:50:52      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:ack   util   memory   err   key   rgs   cat   static   ica   

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>

 

kafka 0.10.2 消息生产者

标签:ack   util   memory   err   key   rgs   cat   static   ica   

原文地址:http://www.cnblogs.com/xiaojf/p/6602695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!