自定义生产者 public class CustomProducer { public static final String brokerList = "宿主机IP:9092"; public static final String topic = "test"; public static Properties initConfig(){ Properties props = new Properties(); //设置kafka地址 props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,brokerList); //ack设置 props.put(ProducerConfig.ACKS_CONFIG,"all"); // 重试次数 props.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG,1); //将消息中对应的key和value做相应的序列化操作来转换成字节数组 props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer"); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer"); //缓存区大小 props.put(ProducerConfig.BUFFER_MEMORY_CONFIG,33554432); //批次大小 props.put(ProducerConfig.BATCH_SIZE_CONFIG,