Spring JDBC - Kafka 消费者的可重试异常

Spring JDBC - Retriable Exceptions for Kafka Consumer

我正在使用 Spring Kafka 消费者读取 Kafka 主题之外的消息。我将这些保存在 Oracle DB 中。每当出现数据库连接错误时,我想执行 retry.I am using Spring JDBC to connect to oracle DB.What are the list of exception 类 that如果我只需要执行重试,我需要添加以防万一 JDBC 连接问题。

private static Map<Class<? extends Throwable>, Boolean> retryableExceptions;

static{
    retryableExceptions = new HashMap<>();
    retryableExceptions.put(Exception.class, true);
}
protected RetryPolicy retryPolicy() {
        SimpleRetryPolicy policy = new SimpleRetryPolicy(maxRetryAttempts, retryableExceptions);
        return policy;
}

我想你只需要这个:

/**
 * Data access exception thrown when a resource fails completely:
 * for example, if we can't connect to a database using JDBC.
 *
 * @author Rod Johnson
 * @author Thomas Risberg
 */
@SuppressWarnings("serial")
public class DataAccessResourceFailureException extends NonTransientDataAccessResourceException {

只要您使用 JdbcTemplate 执行 JDBC 操作,连接的任何低级别错误都将包装到此 DataAccessResourceFailureException 或其子类中。