You can configure your producer until he receives n kcks from the Kafka cluster (request.required.acks) so that you have some kind of guarantee that the data has been fixed correctly before deleting the original file.
If you really need to make sure the message is sent successfully, you can consider an alternative to making a synchronous producer process (producer .type = sync). This way, you can catch any exception caused by a lock call and act accordingly. The exception thrown by send () is kafka.common.FailedToSendMessageException.
Kafka Java API is not perfect, hope this helps you.
source share