REST, HTTP 어댑터 재처리 기능 보완
This commit is contained in:
+8
-8
@@ -88,7 +88,14 @@ public class DeadlineAwareRetryExecutor {
|
|||||||
|
|
||||||
if (!policy.shouldRetryOnStatus(request, status)) {
|
if (!policy.shouldRetryOnStatus(request, status)) {
|
||||||
// 성공 또는 재시도 불필요 → 호출부에서 close 책임
|
// 성공 또는 재시도 불필요 → 호출부에서 close 책임
|
||||||
log.debug("non-retryable response status={}, attempt={}", status, attempt + 1);
|
log.info("non-retryable response status={}, attempt={}", status, attempt + 1);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ④ 마지막 시도였으면 종료
|
||||||
|
if (attempt >= policy.getMaxRetries()) {
|
||||||
|
// 최대 재처리에 도달하여, 재시도하지 않고, 응답 객체를 리턴한다.
|
||||||
|
log.info("최대 재시도 횟수 도달 response status={}, attempt={}", status, attempt + 1);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +134,6 @@ public class DeadlineAwareRetryExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ④ 마지막 시도였으면 바로 종료
|
|
||||||
if (attempt >= policy.getMaxRetries()) break;
|
|
||||||
|
|
||||||
// ⑤ 백오프 대기 전 남은 시간 재확인
|
// ⑤ 백오프 대기 전 남은 시간 재확인
|
||||||
long remainingBeforeWait = totalDeadlineMs - (System.currentTimeMillis() - startTime);
|
long remainingBeforeWait = totalDeadlineMs - (System.currentTimeMillis() - startTime);
|
||||||
if (remainingBeforeWait <= policy.getBackoffMs()) {
|
if (remainingBeforeWait <= policy.getBackoffMs()) {
|
||||||
@@ -171,10 +175,6 @@ public class DeadlineAwareRetryExecutor {
|
|||||||
log.info("RequestConfig = {}", config);
|
log.info("RequestConfig = {}", config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSuccess(int status) {
|
|
||||||
return status >= 200 && status < 300;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeQuietly(CloseableHttpResponse response) {
|
private void closeQuietly(CloseableHttpResponse response) {
|
||||||
try {
|
try {
|
||||||
response.close();
|
response.close();
|
||||||
|
|||||||
+10
-1
@@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.commons.lang3.time.StopWatch;
|
import org.apache.commons.lang3.time.StopWatch;
|
||||||
import org.apache.hc.client5.http.classic.methods.HttpPost;
|
import org.apache.hc.client5.http.classic.methods.HttpPost;
|
||||||
import org.apache.hc.client5.http.config.RequestConfig;
|
import org.apache.hc.client5.http.config.RequestConfig;
|
||||||
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||||
import org.apache.hc.core5.http.ContentType;
|
import org.apache.hc.core5.http.ContentType;
|
||||||
import org.apache.hc.core5.http.HttpHost;
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
@@ -135,7 +136,15 @@ public class HttpClient5AdapterServiceBody extends HttpClient5AdapterServiceSupp
|
|||||||
|
|
||||||
byte[] responseMessage = null;
|
byte[] responseMessage = null;
|
||||||
String responseString = "";
|
String responseString = "";
|
||||||
try (CloseableHttpResponse response = (CloseableHttpResponse) this.client.execute(method, context)) {
|
|
||||||
|
DeadlineAwareRetryExecutor executor =
|
||||||
|
new DeadlineAwareRetryExecutor((CloseableHttpClient)this.client,
|
||||||
|
vo.getConnectionTimeout(),
|
||||||
|
vo.getTimeout());
|
||||||
|
|
||||||
|
// Properties에서 RetryPolicy 로드
|
||||||
|
RetryPolicy policy = RetryPolicy.from(prop); // 설정 로드 방식에 맞게
|
||||||
|
try (CloseableHttpResponse response = (CloseableHttpResponse) executor.execute(method, context, policy)) {
|
||||||
status = response.getCode();
|
status = response.getCode();
|
||||||
responseMessage = EntityUtils.toByteArray(response.getEntity());
|
responseMessage = EntityUtils.toByteArray(response.getEntity());
|
||||||
responseString = new String(responseMessage, vo.getEncode());
|
responseString = new String(responseMessage, vo.getEncode());
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class RetryPolicy {
|
|||||||
|
|
||||||
return new RetryPolicy(getInt(props, RETRY_MAX_RETRIES, 0), getLong(props, RETRY_BACKOFF_MS, 1000L), codes,
|
return new RetryPolicy(getInt(props, RETRY_MAX_RETRIES, 0), getLong(props, RETRY_BACKOFF_MS, 1000L), codes,
|
||||||
getBoolean(props, RETRY_ON_CONNECT_FAIL, false), getBoolean(props, RETRY_ON_TIMEOUT, false),
|
getBoolean(props, RETRY_ON_CONNECT_FAIL, false), getBoolean(props, RETRY_ON_TIMEOUT, false),
|
||||||
getBoolean(props, RETRY_IDEMPOTENT_ONLY, true));
|
getBoolean(props, RETRY_IDEMPOTENT_ONLY, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user