当前位置:   article > 正文

kafka生产消费实例_producerrecord

producerrecord

//生产者

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;


public class FileToKafka {

//    private KafkaProducer<String,String> producer;
    private KafkaProducer<String,byte[]> producer;
    private Properties properties;
    
    public FileToKafka() {
        properties = new Properties();
        properties.put("bootstrap.servers", "master:9092,master:9093");
        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        properties.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
//        producer = new KafkaProducer<String, String>(properties);
        producer = new KafkaProducer<String, byte[]>(properties);
    }
//    public void sendRecorder(String key,String value) {
//        ProducerRecord<String, Stri

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/846046
推荐阅读
相关标签
  

闽ICP备14008679号