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();
}
}
网友评论