429 Too Many Requests 로 실패하는 경우가 많았습니다.
// API Key 2개
@Test
public void testWithApiKeyChange() {
long beforeTime = System.currentTimeMillis();
try {
webClientTest(150, true);
} catch (WebClientResponseException e) {
System.out.println("Response body: " + e.getResponseBodyAsString());
}
long afterTime = System.currentTimeMillis();
double secDiffTime = (double) (afterTime - beforeTime) / 1000.0;
System.out.println("시간차이(s) : " + secDiffTime);
}
// API Key 1개
@Test
public void testWithSingleApiKey() {
long beforeTime = System.currentTimeMillis();
try {
webClientTest(150, false);
} catch (WebClientResponseException e) {
System.out.println("Response body: " + e.getResponseBodyAsString());
}
long afterTime = System.currentTimeMillis();
double secDiffTime = (double) (afterTime - beforeTime) / 1000.0;
System.out.println("시간차이(s) : " + secDiffTime);
}
public void webClientTest(int count, boolean useBothKeys) {
String key = key1;
for (int i = 0; i < count; i++) {
if (useBothKeys) {
key = (i % 2 == 0) ? key1 : key2;
}
System.out.println(find("킴대세", "KR1", key));
System.out.println(i + 1 + "번째");
}
}
public Account find(String nickname, String tag, String riotApiKey) {
Account account = webClient
.get()
.uri("https://asia.api.riotgames.com/riot/account/v1/accounts/by-riot-id/" + nickname + "/" + tag + "?api_key=" + riotApiKey)
.retrieve()
.bodyToMono(Account.class)
.block();
if (account == null) {
throw new AccountNotFoundException();
}
return account;
}
사용자 여러 명의 데이터를 조회하는 그룹 조회가 핵심 기능인 저희 프로젝트 처럼, API 요청 횟수가 많은 기능 요구사항을 가진 프로젝트라면 참고하실만한 방법이 아닐까 싶습니다.
최고의 방법은 아니지만, 하나의 방법으로 생각해주시고 참고 부탁드립니다.