RT。

public void sendData(String brokerList,String topic,List datas){

Properties properties = new Properties();

properties.put("metadata.broker.list",brokerList);

properties.put("producer.type","async");

properties.put("serializer.class", "kafka.serializer.DefaultEncoder");

properties.put("key.serializer.class", "kafka.serializer.StringEncoder");

ProducerConfig producerConfig = new ProducerConfig(properties);

Producer kafkaProducer = new Producer(producerConfig);

List> kms = new ArrayList>();

for(int i=0;i

KeyedMessage km = new KeyedMessage(topic, String.valueOf(i), datas.get(i));

kms.add(km);

}

kafkaProducer.send(kms);

kafkaProducer.close();

}

Logo

Kafka开源项目指南提供详尽教程,助开发者掌握其架构、配置和使用,实现高效数据流管理和实时处理。它高性能、可扩展,适合日志收集和实时数据处理,通过持久化保障数据安全,是企业大数据生态系统的核心。

更多推荐