标签:tst comm rap new catch key col div ace
kafka 均匀发数据函数:
import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import java.io.Serializable; import java.util.List; import java.util.Properties; public class KafkaSendUtil implements Serializable{ public static void sendMsg(String brokerList,String topic,List<String> datas){ Properties properties = new Properties(); properties.put("bootstrap.servers",brokerList); properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer"); properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer"); KafkaProducer producer = null; try{ producer = new KafkaProducer(properties); for(int i=0;i<datas.size();i++){ ProducerRecord<String,String> message = new ProducerRecord<String, String>(topic,datas.get(i)); producer.send(message); } }catch(Exception ex){ ex.printStackTrace(); }finally{ if(producer != null){ producer.close(); } } } }
标签:tst comm rap new catch key col div ace
原文地址:https://www.cnblogs.com/lihao7/p/9197620.html