demo-SimpleProducer

2018-07-18  本文已影响0人  0ba95e9513d3

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();

    }

}

上一篇下一篇

猜你喜欢

热点阅读