2
我們可以像這樣創建一個集羣實例。Cassandra Datastax驅動程序重試策略
cluster = Cluster
.builder()
.addContactPoint("192.168.0.30")
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.build();
我們將提供詢問時請求重試的次數信息。
任何意見表示讚賞。
感謝
我們可以像這樣創建一個集羣實例。Cassandra Datastax驅動程序重試策略
cluster = Cluster
.builder()
.addContactPoint("192.168.0.30")
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.build();
我們將提供詢問時請求重試的次數信息。
任何意見表示讚賞。
感謝
爲了指定這些值,你必須創建自己的實施RetryPolicy
interface的。
以下僅僅是一個例子 - 使自己實現以下的規則:
public class CustomRetryPolicy implements RetryPolicy {
private final int readAttempts;
private final int writeAttempts;
private final int unavailableAttempts;
public CustomRetryPolicy(int readAttempts, int writeAttempts, int unavailableAttempts) {
this.readAttempts = readAttempts;
this.writeAttempts = writeAttempts;
this.unavailableAttempts = unavailableAttempts;
}
@Override
public RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, boolean dataReceived, int rTime) {
if (dataReceived) {
return RetryDecision.ignore();
} else if (rTime < readAttempts) {
return RetryDecision.retry(cl);
} else {
return RetryDecision.rethrow();
}
}
@Override
public RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl, WriteType wt, int requiredResponses, int receivedResponses, int wTime) {
if (wTime < writeAttempts) {
return RetryDecision.retry(cl);
}
return RetryDecision.rethrow();
}
@Override
public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) {
if (uTime < unavailableAttempts) {
return RetryDecision.retry(ConsistencyLevel.ONE);
}
return RetryDecision.rethrow();
}
}
這是很容易做到......然後,你將在你的Cluster
...
RetryPolicy rc = new CustomRetryPolicy(3, 3, 2);
Cluster cluster = Cluster.builder().addContactPoint("192.168.0.30").withRetryPolicy(rc).build();
HTH, 卡羅
什麼是重試政策默認的重試次數,與卡斯走來安德拉。?? – Jobs
只有一次......據我所知,所有的默認實現只重試一次......有一個默認的實現,它以較低的一致性級別重試。 –
謝謝你的幫助。 – Jobs