Java Producer: Synchronous send vs Asynchronous send

75 views
Skip to first unread message

SMJ

unread,
May 12, 2018, 10:11:48 PM5/12/18
to Confluent Platform
We have an application which sends items in a list to a kafka topic. The item will be removed from the list only if there were no exceptions encountered while sending. How can I implement this using the onCompletion() method in asynchronous send() ?
- We don't want to use synchronous send() because of the performance issues. Does synchronous send() block until the message has been received by the topic? 
kafkaProducer.send(new ProducerRecord<>(topic, null, value, key, value), new Callback() {
   @Override
public void onCompletion(RecordMetadata recordMetadata, Exception e) {
         success = true;
         if (e == null) {
           LOG.info("Successfully sent to topic: " + topic);

          } else {
           Log.error("Exception");
         }



xinyi...@gmail.com

unread,
May 15, 2018, 2:33:33 AM5/15/18
to Confluent Platform
KafkaProducer.send() is asynchronous.
The send() method is asynchronous. When called it adds the record to a buffer of pending record sends and immediately returns. This allows the producer to batch together individual records for efficiency.
Reply all
Reply to author
Forward
0 new messages