0

I am browsing in the docs and can see that there is functions that would be really useful, however going further I realized that they not existing anymore or I am wrong? I would like to perform a business logic based on exception type -> or in more details i would like to avoid retries if exception type of my customer one.

This is what i found in 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});

Any suggestions would be appreciated, i do not want to use annotation @Retryble

  • You may refer to this answer with an example I've [posted here](https://stackoverflow.com/a/67089702/9951983). – Rahul Dey Apr 14 '21 at 10:18
  • You may refer to this answer with an example in [this post](https://stackoverflow.com/a/67089702/9951983). – Rahul Dey Apr 14 '21 at 10:21

1 Answers1

0

Exactly where did you find that documentation?

See the javadocs for 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);
    }

You add retryable/not retryable exceptions and determine whether we should traverse the cause tree until we find a match (there are also constructors with fewer parameters if you want to take the defaults).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Hey Gary thanks for your comment, i got the info from the following source? https://docs.spring.io/spring-batch/docs/current/reference/html/retry.html#retryTemplate , what approach would you suggest personally? – artjom prozorov Jul 12 '20 at 17:26
  • I opened [an issue against the batch documentation](https://github.com/spring-projects/spring-batch/issues/3744). `>what approach would you suggest personally?`. I am not sure what you mean; just use the constructor as I indicated in my answer. – Gary Russell Jul 13 '20 at 13:35