title: ListenableFuture - how to wait before return
body: <p>I have a Spring Cloud microservice that posts message on a Kafka broker, this microservice is accessible thru a REST api.</p>
  
  <p>I want to return the submit status back to the caller but seems like Java does not await. How to make this to wait either success or failure before my code returns?</p>
  
  <p>Heres the code:</p>
  
  <pre><code>kafkaProduc.send("topictest", msg).addCallback(
                  new ListenableFutureCallback&lt;SendResult&lt;String, ExecutionDataMessage&gt;&gt;() {
      @Override
      public void onSuccess(SendResult&lt;String, ExecutionDataMessage&gt; result) {
          eresp.status = "ok";
          eresp.msg = "message submitted successfully";
      }
  
      @Override
      public void onFailure(Throwable ex) {
          eresp.status = "error";
          eresp.msg = "failure while sending data to kafka. exception: " + ex.getMessage();
      }
  });
  HttpStatus erespStatus = eresp.status == "ok" ? HttpStatus.CREATED : HttpStatus.BAD_REQUEST;
  return new ResponseEntity&lt;ExecutionResponse&gt;(eresp, erespStatus);
  </code></pre>