I am using play framework and Apache Kafka.
I have a POST method which sends a message to Kafka. Kafka has an API method
public java.util.concurrent.Future send
After some searching found the answer with some help from this one.
Following is the code
RedeemablePromise<Result> promise = RedeemablePromise.empty();
kafkaProducer.send(record, (metadata, ex) -> {
if (ex != null) {
promise.failure(ex);
} else {
promise.success(created(Json.toJson(new ProduceResult())));
}
});