diff --git a/user-api/src/main/java/com/biengual/userapi/config/OpenSearchConfig.java b/user-api/src/main/java/com/biengual/userapi/config/OpenSearchConfig.java index f54bc213..75dce055 100644 --- a/user-api/src/main/java/com/biengual/userapi/config/OpenSearchConfig.java +++ b/user-api/src/main/java/com/biengual/userapi/config/OpenSearchConfig.java @@ -1,5 +1,7 @@ package com.biengual.userapi.config; +import java.util.concurrent.TimeUnit; + import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -15,6 +17,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; + +@Slf4j @Configuration public class OpenSearchConfig { @@ -47,9 +52,20 @@ public OpenSearchClient openSearchClient() { // RestClient 빌더에 인증 제공자 추가 RestClient restClient = RestClient.builder(new HttpHost(host, port, protocol)) - .setHttpClientConfigCallback( + .setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder - -> httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider)) + .setDefaultCredentialsProvider(credentialsProvider) + .setConnectionTimeToLive(5, TimeUnit.MINUTES) + .setKeepAliveStrategy( + (response, context) -> TimeUnit.MINUTES.toMillis(5) + ) + ) + .setRequestConfigCallback(requestConfigBuilder -> + requestConfigBuilder + .setSocketTimeout(60000) + .setConnectTimeout(5000) + .setConnectionRequestTimeout(0) + ) .build(); // OpenSearch 클라이언트 생성 및 반환 diff --git a/user-api/src/main/java/com/biengual/userapi/config/OpenSearchContentConfig.java b/user-api/src/main/java/com/biengual/userapi/config/OpenSearchContentConfig.java index 0abc16ce..37b60392 100644 --- a/user-api/src/main/java/com/biengual/userapi/config/OpenSearchContentConfig.java +++ b/user-api/src/main/java/com/biengual/userapi/config/OpenSearchContentConfig.java @@ -12,8 +12,11 @@ import com.biengual.core.response.error.exception.CommonException; +import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Configuration @RequiredArgsConstructor public class OpenSearchContentConfig { @@ -22,6 +25,7 @@ public class OpenSearchContentConfig { /** * 인덱스가 없을 경우 인덱스 초기화 */ + @PostConstruct public void init() { this.createIndexIfNotExists(openSearchClient); } @@ -73,6 +77,7 @@ private void createIndexIfNotExists(OpenSearchClient client) { client.indices().create(createIndexRequest); } } catch (Exception e) { + log.error(e.getMessage(), e); throw new CommonException(SEARCH_CONTENT_SAVE_FAILED); } }