Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOTFIX] OpenSearch DEV 연결 테스트 #460

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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 클라이언트 생성 및 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,6 +25,7 @@ public class OpenSearchContentConfig {
/**
* 인덱스가 없을 경우 인덱스 초기화
*/
@PostConstruct
public void init() {
this.createIndexIfNotExists(openSearchClient);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading