美文网首页
demo-SimpleProducer

demo-SimpleProducer

作者: 0ba95e9513d3 | 来源:发表于2018-07-18 11:08 被阅读0次

    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;

    public class SimpleProducer {

    public static void main(String[] args)throws Exception {

    String topicName ="abcd";

            Properties props =new Properties();

            props.put("bootstrap.servers", "192.168.2.128:9092");

            props.put("client.id", "2");

            props.put("acks", "all");

            props.put("retries", 0);

            props.put("batch.size", 16384);

            props.put("linger.ms", 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 producer =new KafkaProducer(props);

            producer.send(new ProducerRecord(topicName, "qqq"));

            System.out.println("Message sent successfully");

            producer.close();

        }

    }

    相关文章

      网友评论

          本文标题:demo-SimpleProducer

          本文链接:https://www.haomeiwen.com/subject/fbcopftx.html