zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    C语言第九节 函数指针
    C语言第七节 指针
    C语言第五节 函数
    C语言第六节 结构体
    C语言第四节 数组
    C语言第三节 循环结构
    C语言第二节 分支结构
    ARC、MRC混编
    Git 和 SVN之间的五个基本区别
    KZ--NSString、NSMutableString
  • 原文地址:https://www.cnblogs.com/xiaojf/p/6602695.html
Copyright © 2011-2022 走看看