简单重试策略 Spring
SimpleRetryPolicy Spring
我正在浏览文档,可以看到有一些功能非常有用,但是进一步我意识到它们不再存在或者我错了?我想根据异常类型执行业务逻辑 -> 或者更详细地说,如果我的客户的异常类型是我想避免重试。
这是我在 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
您究竟是在哪里找到该文档的?
查看 SimpleRetryPolicy
...
的 javadoc
/**
* 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);
}
您添加 retryable/not 可重试异常并确定我们是否应该遍历原因树直到找到匹配项(如果您想采用默认值,也有参数较少的构造函数)。
我正在浏览文档,可以看到有一些功能非常有用,但是进一步我意识到它们不再存在或者我错了?我想根据异常类型执行业务逻辑 -> 或者更详细地说,如果我的客户的异常类型是我想避免重试。
这是我在 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
您究竟是在哪里找到该文档的?
查看 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);
}
您添加 retryable/not 可重试异常并确定我们是否应该遍历原因树直到找到匹配项(如果您想采用默认值,也有参数较少的构造函数)。