SimpleRetryPolicy Spring - PullRequest
       19

SimpleRetryPolicy Spring

0 голосов
/ 10 июля 2020

Я просматриваю документы и вижу, что есть функции, которые были бы действительно полезны, однако, идя дальше, я понял, что они больше не существуют, или я ошибаюсь? Я хотел бы выполнить бизнес-лог c на основе типа исключения -> или, более подробно, я бы хотел избежать повторных попыток, если тип исключения моего клиента один.

Это то, что я нашел в docs.spring .io

 SimpleRetryPolicy policy = new SimpleRetryPolicy();
// Set the max retry attempts
policy.setMaxAttempts(5);
// Retry on all exceptions (this is the default)
policy.setRetryableExceptions(new Class[] {Exception.class});
// ... but never retry IllegalStateException
policy.setFatalExceptions(new Class[] {IllegalStateException.class});

Любые предложения приветствуются, я не хочу использовать аннотацию @ Retryble

1 Ответ

0 голосов
/ 10 июля 2020

Где именно вы нашли эту документацию?

См. Javadocs для SimpleRetryPolicy ...

    /**
     * Create a {@link SimpleRetryPolicy} with the specified number of retry attempts. If
     * traverseCauses is true, the exception causes will be traversed until a match is
     * found. The default value indicates whether to retry or not for exceptions (or super
     * classes) are not found in the map.
     * @param maxAttempts the maximum number of attempts
     * @param retryableExceptions the map of exceptions that are retryable based on the
     * map value (true/false).
     * @param traverseCauses is this clause traversable
     * @param defaultValue the default action.
     */
    public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions,
            boolean traverseCauses, boolean defaultValue) {
        super();
        this.maxAttempts = maxAttempts;
        this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions, defaultValue);
        this.retryableClassifier.setTraverseCauses(traverseCauses);
    }

Вы добавляете повторяющиеся / неповторяемые исключения и определяете, должны ли мы пересекать вызвать дерево до тех пор, пока мы не найдем совпадение (есть также конструкторы с меньшим количеством параметров, если вы хотите использовать значения по умолчанию).

...