Wednesday 13 November 2019

Java: Kafka: Synchronize the production of messages


KafkaProducer send method is used to publish a record to a topic. As you see the signature of send() method it return a Future.

public Future<RecordMetadata> send(ProducerRecord<K, V> record, Callback callback)
public Future<RecordMetadata> send(ProducerRecord<K, V> record)

We can call the 'get()' method on the Future instance to make the publishing of messages synchronous.

Note
Do not make the message production synchronous in production, it leads to performance issues.

Previous                                                    Next                                                    Home

No comments:

Post a Comment