diff --git a/examples/main/java/io/milvus/GeneralExample.java b/examples/main/java/io/milvus/GeneralExample.java index f29b1be2f..0a4b0a6a5 100644 --- a/examples/main/java/io/milvus/GeneralExample.java +++ b/examples/main/java/io/milvus/GeneralExample.java @@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject; import com.google.protobuf.ByteString; +import io.milvus.client.MilvusClient; import io.milvus.client.MilvusServiceClient; import io.milvus.common.clientenum.ConsistencyLevelEnum; import io.milvus.common.utils.JacksonUtils; @@ -44,7 +45,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////// public class GeneralExample { - private static final MilvusServiceClient milvusClient; + private static final MilvusClient milvusClient; static { ConnectParam connectParam = ConnectParam.newBuilder() @@ -52,7 +53,10 @@ public class GeneralExample { .withPort(19530) .withAuthorization("root","Milvus") .build(); - milvusClient = new MilvusServiceClient(connectParam); + RetryParam retryParam = RetryParam.newBuilder() + .withMaxRetryTimes(3) + .build(); + milvusClient = new MilvusServiceClient(connectParam).withRetry(retryParam); } private static final String COLLECTION_NAME = "java_sdk_example_general"; diff --git a/src/main/java/io/milvus/client/MilvusServiceClient.java b/src/main/java/io/milvus/client/MilvusServiceClient.java index 287977592..f54d50187 100644 --- a/src/main/java/io/milvus/client/MilvusServiceClient.java +++ b/src/main/java/io/milvus/client/MilvusServiceClient.java @@ -316,8 +316,10 @@ private R retry(Callable> callable) { // for server-side returned error, only retry for rate limit // in new error codes of v2.3, rate limit error value is 8 - if (!(serverException.getCompatibleCode() == ErrorCode.RateLimit - || serverException.getStatus() == 8)) { + if (retryParam.isRetryOnRateLimie() && + (serverException.getCompatibleCode() == ErrorCode.RateLimit || + serverException.getStatus() == 8)) { + } else { return resp; } } else {