private boolean canRetry(ProducerBatch batch, ProduceResponse.PartitionResponse response, long now) {
        return !batch.hasReachedDeliveryTimeout(accumulator.getDeliveryTimeoutMs(), now) &&
            batch.attempts() < this.retries &&
            !batch.isDone() &&
            (transactionManager == null ?
                    response.error.exception() instanceof RetriableException :
                    transactionManager.canRetry(response, batch));
    }
We can retry a send if the error is transient and the number of attempts taken is fewer than the maximum allowed.
We can also retry OutOfOrderSequence exceptions for future batches, since if the first batch has failed, the
future batches are certain to fail with an OutOfOrderSequence exception.
clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java