当前位置:   article > 正文

kafka send方法小结_kafka.send

kafka.send

1、kafka的send 默认发送方式应该是同步,而非异步

public ApacheKafkaClient(String kafkaServers, boolean sync) throws Exception {
    super(kafkaServers, sync);
}
  • 1
  • 2
  • 3

查看父类VersionKafkaClient

2、kafka调用send方法有3种方式
//单条发送

public void send(String topic, String message) throws Exception {
    if (topic != null && message != null) {
        ProducerRecord<String, String> record = new ProducerRecord(topic, message);
        if (this.sync) {
            this.producer.send(record).get();
        } else {
            this.producer.send(record);
        }

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

//批量发送

public void send(String topic, Collection<String> messages) throws Exception {
    I
  • 1
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号