header-logo.png GKINDEX

Kafka Producer Sending Message Synchronously

Earlier example, we have sent a message without knowing the result of a sent message.

In this example will send a message will wait until the result comes(either sucess or failure),this mechanism called as a synchronous message send

Kafka producer synchronous send example

The above example will wait until the result appears, it can be either a success or a failure.

The major difference from the above example to previous one is "RecordMetadata metadata=producer.send(record).get()" , this step makes to wait until the result comes unlike the previous.
  • Share