ai-service Redis 설정 수정 및 실행 프로파일 업데이트

주요 변경사항:
- Redis Sentinel 모드에서 Standalone 모드로 변경
- RedisConfig.java: RedisSentinelConfiguration → RedisStandaloneConfiguration
- AiServiceApplication 실행 프로파일 수정:
  * 메인 클래스: AiApplication → AiServiceApplication
  * 포트: 8081 → 8083
  * Claude API 설정 추가 (URL, API Key, Model)
  * Kafka 토픽 설정 추가
- application.yml: Redis 단일 인스턴스 설정으로 통일
- RecommendationGenerationException 클래스 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wonho 2025-10-31 11:24:15 +09:00
parent 5b0d3f5289
commit 2314156afe
4 changed files with 48 additions and 36 deletions

View File

@ -2,7 +2,7 @@
<configuration default="false" name="AiServiceApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<option name="ACTIVE_PROFILES" />
<module name="kt-event-marketing.ai-service.main" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.kt.ai.AiApplication" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.kt.ai.AiServiceApplication" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.kt.ai.*" />
@ -10,19 +10,25 @@
</pattern>
</extension>
<envs>
<env name="SERVER_PORT" value="8081" />
<env name="DB_HOST" value="4.230.112.141" />
<env name="DB_PORT" value="5432" />
<env name="DB_NAME" value="aidb" />
<env name="DB_USERNAME" value="eventuser" />
<env name="DB_PASSWORD" value="Hi5Jessica!" />
<env name="SERVER_PORT" value="8083" />
<env name="REDIS_HOST" value="20.214.210.71" />
<env name="REDIS_PORT" value="6379" />
<env name="REDIS_PASSWORD" value="Hi5Jessica!" />
<env name="REDIS_DATABASE" value="3" />
<env name="KAFKA_BOOTSTRAP_SERVERS" value="20.249.182.13:9095,4.217.131.59:9095" />
<env name="KAFKA_CONSUMER_GROUP" value="ai" />
<env name="JPA_DDL_AUTO" value="update" />
<env name="JPA_SHOW_SQL" value="false" />
<env name="KAFKA_CONSUMER_GROUP" value="ai-service-consumers" />
<env name="KAFKA_TOPICS_AI_JOB" value="ai-event-generation-job" />
<env name="KAFKA_TOPICS_AI_JOB_DLQ" value="ai-event-generation-job-dlq" />
<env name="AI_PROVIDER" value="CLAUDE" />
<env name="AI_CLAUDE_API_URL" value="https://api.anthropic.com/v1/messages" />
<env name="AI_CLAUDE_API_KEY" value="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" />
<env name="AI_CLAUDE_ANTHROPIC_VERSION" value="2023-06-01" />
<env name="AI_CLAUDE_MODEL" value="claude-sonnet-4-5-20250929" />
<env name="AI_CLAUDE_MAX_TOKENS" value="4096" />
<env name="AI_CLAUDE_TEMPERATURE" value="0.7" />
<env name="LOG_LEVEL_ROOT" value="INFO" />
<env name="LOG_LEVEL_AI" value="DEBUG" />
<env name="LOG_LEVEL_KAFKA" value="INFO" />
</envs>
<method v="2">
<option name="Make" enabled="true" />

View File

@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@ -17,7 +17,6 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSeriali
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.time.Duration;
import java.util.Arrays;
/**
* Redis 설정
@ -30,11 +29,11 @@ import java.util.Arrays;
@Configuration
public class RedisConfig {
@Value("${spring.data.redis.sentinel.master:mymaster}")
private String sentinelMaster;
@Value("${spring.data.redis.host}")
private String redisHost;
@Value("${spring.data.redis.sentinel.nodes}")
private String sentinelNodes;
@Value("${spring.data.redis.port}")
private int redisPort;
@Value("${spring.data.redis.password}")
private String redisPassword;
@ -46,26 +45,18 @@ public class RedisConfig {
private long redisTimeout;
/**
* Redis 연결 팩토리 설정 (Sentinel 모드)
* Redis 연결 팩토리 설정 (Standalone 모드)
*/
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
.master(sentinelMaster);
// Sentinel 노드 추가 (콤마로 구분된 host:port 형식)
Arrays.stream(sentinelNodes.split(","))
.map(String::trim)
.forEach(node -> {
String[] parts = node.split(":");
sentinelConfig.sentinel(parts[0], Integer.parseInt(parts[1]));
});
RedisStandaloneConfiguration redisConfig = new RedisStandaloneConfiguration();
redisConfig.setHostName(redisHost);
redisConfig.setPort(redisPort);
redisConfig.setDatabase(redisDatabase);
if (redisPassword != null && !redisPassword.isEmpty()) {
sentinelConfig.setPassword(redisPassword);
sentinelConfig.setSentinelPassword(redisPassword);
redisConfig.setPassword(redisPassword);
}
sentinelConfig.setDatabase(redisDatabase);
// Lettuce Client 설정: Timeout Connection 옵션
SocketOptions socketOptions = SocketOptions.builder()
@ -83,7 +74,7 @@ public class RedisConfig {
.clientOptions(clientOptions)
.build();
return new LettuceConnectionFactory(sentinelConfig, clientConfig);
return new LettuceConnectionFactory(redisConfig, clientConfig);
}
/**

View File

@ -0,0 +1,17 @@
package com.kt.ai.exception;
/**
* 추천 생성 발생한 예외
*
* @author AI Service Team
* @since 1.0.0
*/
public class RecommendationGenerationException extends AIServiceException {
public RecommendationGenerationException(String message) {
super("RECOMMENDATION_GENERATION_FAILED", message);
}
public RecommendationGenerationException(String message, Throwable cause) {
super("RECOMMENDATION_GENERATION_FAILED", message, cause);
}
}

View File

@ -2,16 +2,14 @@ spring:
application:
name: ai-service
# Redis Configuration with Sentinel
# Redis Configuration
data:
redis:
host: ${REDIS_HOST:20.214.210.71}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:Hi5Jessica!}
database: ${REDIS_DATABASE:3}
timeout: ${REDIS_TIMEOUT:3000}
sentinel:
master: ${REDIS_SENTINEL_MASTER:mymaster}
nodes: ${REDIS_SENTINEL_NODES:redis-node-0.redis-headless.kt-event-marketing.svc.cluster.local:26379,redis-node-1.redis-headless.kt-event-marketing.svc.cluster.local:26379}
password: ${REDIS_PASSWORD:Hi5Jessica!}
lettuce:
pool:
max-active: ${REDIS_POOL_MAX:8}