@Override
 public void close() throws Exception {
   LOG.info("Closing producer");
   super.close();
   KinesisProducer kp = this.producer;
   this.producer = null;
   if (kp != null) {
     LOG.info("Flushing outstanding {} records", kp.getOutstandingRecordsCount());
     // try to flush all outstanding records
     while (kp.getOutstandingRecordsCount() > 0) {
       kp.flush();
       try {
         Thread.sleep(500);
       } catch (InterruptedException e) {
         LOG.warn("Flushing was interrupted.");
         // stop the blocking flushing and destroy producer immediately
         break;
       }
     }
     LOG.info("Flushing done. Destroying producer instance.");
     kp.destroy();
   }
 }