如何在kafka生产者中传递多个数据?

时间:2016-10-20 05:18:53

标签: java apache-kafka distributed-computing kafka-consumer-api kafka-producer-api

需要传递多个数据(对象)以及文件数据

是否有可用于传递对象或任何方式的序列化程序?

以下是仅传递文件数据的代码

props.put("bootstrap.servers", "localhost:9092");
        props.put("metadata.broker.list", "localhost:9093");

        props.put("producer.type", "async");
        props.put("batch.size", "500");
        props.put("compression.codec", "1");
        props.put("compression.topic", "WRA");
        // props.put("key.serializer",
        // "org.apache.kafka.common.serialization.StringSerializer");
        props.put("key.serializer", "org.apache.kafka.common.serialization.IntegerSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");

        org.apache.kafka.clients.producer.Producer<Integer, byte[]> producer = new KafkaProducer<Integer, byte[]>(
                props);

        producer.send(new ProducerRecord<Integer, byte[]>("topic1", file.getBytes()));

0 个答案:

没有答案