2017-10-04 44 views
1

我正在使用Spring Kafka使用者讀取關於Kafka主題的消息。我堅持Oracle數據庫。無論何時出現數據庫連接錯誤,我想執行重試。我正在使用Spring JDBC連接到Oracle DB。如果需要僅重試JDBC連接問題,那麼需要添加哪些異常類列表。Spring JDBC - Kafka Consumer的可重複例外

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; 
} 

回答

1

我認爲你需要僅僅只有這一個:

/** 
* 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或它的子類。

+0

再次感謝Artem! –

相關問題