Encountered the same error. Calling kafkaTemplate.flush() helped me, as it forcibly delivers all messages from the buffer.
kafkaTemplate.flush()