title: Exception Handling on sending a message via Kafka Template
body: <p>I was wondering if there is a way to catch an exception/throwable when producing a kafka message via the Kafka Template.</p>
  
  <p>I don't see anything where it would throw a KafkaException if something fails. I need to find out if the message was committed to Kafka before I can continue with my application flow. I know the ListenableFuture would  log a failure but I don't know how to capture that onFailure.</p>
  
  <pre><code>public void sendToKafkaTopic(KafkaMessage data) {
  
      ListenableFuture&lt;SendResult&lt;String, KafkaMessage&gt;&gt; future = kafkaTemplate.send(primaryKafkaTopic, data);
      future.addCallback(new ListenableFutureCallback&lt;SendResult&lt;String, KafkaMessage&gt;&gt;() {
  
        @Override
        public void onSuccess(SendResult&lt;String, KafkaMessage&gt; result) {
          log.info("sent message='{}' with offset={}", data,
              result.getRecordMetadata().offset());
        }
  
        @Override
        public void onFailure(Throwable ex) {
          log.error("unable to send message='{}'", data, ex);
        }
      });
    }
  </code></pre>
  
  <p>I was trying to find something like this:</p>
  
  <pre><code>  public void sendToKafkaTopic(KafkaMessage data) {
  
      try {
        kafkaTemplate.send(primaryKafkaTopic, data);
      } catch (RuntimeException err) {
        log.error("unable to send message='{}'", data, ex);
        throw new CustomException(err);
      }
    }
  }
  </code></pre>