Skip to content

Commit 77fa201

Browse files
committed
feat: commit을 위한 commit
1 parent 0cbe505 commit 77fa201

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/location/controller/KakaoApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class KakaoApiController {
4242
@Operation(
4343
summary = "주변 음식점 조회",
4444
description = "좌표(서울 시청 근처)로 카카오 로컬에서 주변 음식점을 조회합니다, 좌표는 입력하면 됩니다." +
45-
"예시 : http://localhost:8080/api/v1/location/kakao/restaurant?lat=37.5665&lon=126.9780"
45+
"예시 : http://localhost:8080/api/v1/location/kakao/restaurant?x=126.9780&y=37.5665&"
4646
)
4747
@PostMapping("/restaurant")
4848
public List<KakaoLocalResponse.Document> KakaoRestaurants(
@@ -56,7 +56,7 @@ public List<KakaoLocalResponse.Document> KakaoRestaurants(
5656
@Operation(
5757
summary = "주변 카페 조회",
5858
description = "좌표(서울 시청 근처)로 카카오 로컬에서 주변 카페를 조회합니다, 좌표는 입력하면 됩니다." +
59-
"예시 : http://localhost:8080/api/v1/location/kakao/cafes?lat=37.5665&lon=126.9780"
59+
"예시 : http://localhost:8080/api/v1/location/kakao/cafes?x=126.9780&y=37.5665"
6060
)
6161
@PostMapping("/cafes")
6262
public List<KakaoLocalResponse.Document> KakaoCafes(

src/main/java/com/back/web7_9_codecrete_be/domain/location/service/KakaoLocalService.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import com.back.web7_9_codecrete_be.global.error.code.LocationErrorCode;
1010
import com.back.web7_9_codecrete_be.global.error.exception.BusinessException;
1111
import lombok.RequiredArgsConstructor;
12+
import org.springframework.retry.annotation.Backoff;
13+
import org.springframework.retry.annotation.Retryable;
1214
import org.springframework.stereotype.Service;
15+
import org.springframework.web.client.HttpServerErrorException;
16+
import org.springframework.web.client.ResourceAccessException;
1317
import org.springframework.web.client.RestClient;
1418

1519
import java.util.List;
@@ -22,15 +26,23 @@ public class KakaoLocalService {
2226
private final RestClient kakaoMobilityClient;
2327

2428
// 해당 좌표의 1km 근방에 존재하는 음식점를 거리순으로 나타냄
29+
@Retryable( //최초 1번, 재시도 2번 시도
30+
retryFor = {HttpServerErrorException.class, ResourceAccessException.class}, //외부 서버의 문제, 네트워크, 타임아웃 문제인 경우에 재시도
31+
backoff = @Backoff(delay = 200, multiplier = 2.0) //0.2초, 0.4초, 0.8초 순으로 재시도
32+
)
2533
public List<KakaoLocalResponse.Document> searchNearbyRestaurants(double lat, double lng) {
26-
34+
//좌표의 소수점 숫자가 다르면 매번 다른 캐싱을 해야하니, 통일시켜줌
35+
lat = Math.round(lat * 10000) / 10000.0;
36+
lng = Math.round(lng * 10000) / 10000.0;
37+
final double y = lat;
38+
final double x = lng;
2739
return kakaoRestClient.get()
2840
.uri(uriBuilder -> uriBuilder
2941
.path("/v2/local/search/keyword.json")
3042
.queryParam("query", "음식점")
3143
.queryParam("category_group_code", "FD6")
32-
.queryParam("x", lng)
33-
.queryParam("y", lat)
44+
.queryParam("x", x)
45+
.queryParam("y", y)
3446
.queryParam("radius", 1000) // 반경 1km
3547
.queryParam("sort", "distance")
3648
.build()
@@ -41,15 +53,24 @@ public List<KakaoLocalResponse.Document> searchNearbyRestaurants(double lat, dou
4153
}
4254

4355
// 해당 좌표의 1km 근방에 존재하는 카페를 거리순으로 나타냄
44-
public List<KakaoLocalResponse.Document> searchNearbyCafes(double lat, double lng) {
45-
56+
@Retryable( //최초 1번, 재시도 2번 시도
57+
retryFor = {HttpServerErrorException.class, ResourceAccessException.class}, //외부 서버의 문제, 네트워크, 타임아웃 문제인 경우에 재시도
58+
backoff = @Backoff(delay = 200, multiplier = 2.0) //0.2초, 0.4초, 0.8초 순으로 재시도
59+
)
60+
public List<KakaoLocalResponse.Document> searchNearbyCafes(double lat, double lng) {
61+
62+
//좌표의 소수점 숫자가 다르면 매번 다른 캐싱을 해야하니, 통일시켜줌
63+
lat = Math.round(lat * 10000) / 10000.0;
64+
lng = Math.round(lng * 10000) / 10000.0;
65+
final double y = lat;
66+
final double x = lng;
4667
return kakaoRestClient.get()
4768
.uri(uriBuilder -> uriBuilder
4869
.path("/v2/local/search/keyword.json")
4970
.queryParam("query", "카페")
5071
.queryParam("category_group_code", "CE7")
51-
.queryParam("x", lng)
52-
.queryParam("y", lat)
72+
.queryParam("x", x)
73+
.queryParam("y", y)
5374
.queryParam("radius", 1000) // 반경 1km
5475
.queryParam("sort", "distance")
5576
.build()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.back.web7_9_codecrete_be.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.retry.annotation.EnableRetry;
5+
6+
@EnableRetry
7+
@Configuration
8+
public class RetryConfig {
9+
}

src/main/java/com/back/web7_9_codecrete_be/global/config/WebClientConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.http.HttpHeaders;
77
import org.springframework.http.MediaType;
88
import org.springframework.http.client.ClientHttpRequestInterceptor;
9+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
910
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
1011
import org.springframework.web.client.RestClient;
1112
import org.springframework.web.client.RestTemplate;
@@ -70,7 +71,12 @@ public RestTemplate restTemplate() {
7071
@Bean
7172
public RestClient kakaoRestClient(){
7273

74+
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
75+
factory.setConnectionRequestTimeout(3_000);
76+
factory.setReadTimeout(5_000);
77+
7378
return RestClient.builder()
79+
.requestFactory(factory)
7480
.baseUrl(kakaoBaseUrl)
7581
.defaultHeader("Authorization", kakaomapApiKey)
7682
.build();

0 commit comments

Comments
 (0)