mirror of
https://github.com/ktds-dg0501/kt-event-marketing.git
synced 2025-12-06 08:06:25 +00:00
샘플 토픽명으로 변경 (sample. 접두사 추가)
- 다른 서비스 개발자들의 운영 토픽과 충돌 방지 - MVP용 샘플 토픽: sample.event.created, sample.participant.registered, sample.distribution.completed - KafkaTopicConfig, SampleDataLoader, 3개 Consumer 모두 업데이트 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
31fb1c541b
commit
4c8165bd20
@ -15,7 +15,11 @@
|
|||||||
"Bash(git add:*)",
|
"Bash(git add:*)",
|
||||||
"Bash(git commit:*)",
|
"Bash(git commit:*)",
|
||||||
"Bash(git push)",
|
"Bash(git push)",
|
||||||
"Bash(git pull:*)"
|
"Bash(git pull:*)",
|
||||||
|
"Bash(netstat:*)",
|
||||||
|
"Bash(findstr:*)",
|
||||||
|
"Bash(./gradlew analytics-service:compileJava:*)",
|
||||||
|
"Bash(python -m json.tool:*)"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,53 @@
|
|||||||
|
package com.kt.event.analytics.config;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.admin.NewTopic;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.kafka.config.TopicBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kafka 토픽 자동 생성 설정
|
||||||
|
*
|
||||||
|
* ⚠️ MVP 전용: 샘플 데이터용 토픽을 생성합니다.
|
||||||
|
* 실제 운영 토픽(event.created 등)과 구분하기 위해 "sample." 접두사 사용
|
||||||
|
*
|
||||||
|
* 서비스 시작 시 필요한 Kafka 토픽을 자동으로 생성합니다.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty(name = "spring.kafka.enabled", havingValue = "true", matchIfMissing = false)
|
||||||
|
public class KafkaTopicConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sample.event.created 토픽 (MVP 샘플 데이터용)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public NewTopic eventCreatedTopic() {
|
||||||
|
return TopicBuilder.name("sample.event.created")
|
||||||
|
.partitions(3)
|
||||||
|
.replicas(1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sample.participant.registered 토픽 (MVP 샘플 데이터용)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public NewTopic participantRegisteredTopic() {
|
||||||
|
return TopicBuilder.name("sample.participant.registered")
|
||||||
|
.partitions(3)
|
||||||
|
.replicas(1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sample.distribution.completed 토픽 (MVP 샘플 데이터용)
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public NewTopic distributionCompletedTopic() {
|
||||||
|
return TopicBuilder.name("sample.distribution.completed")
|
||||||
|
.partitions(3)
|
||||||
|
.replicas(1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -52,10 +52,10 @@ public class SampleDataLoader implements ApplicationRunner {
|
|||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
// Kafka Topic Names
|
// Kafka Topic Names (MVP용 샘플 토픽)
|
||||||
private static final String EVENT_CREATED_TOPIC = "event.created";
|
private static final String EVENT_CREATED_TOPIC = "sample.event.created";
|
||||||
private static final String PARTICIPANT_REGISTERED_TOPIC = "participant.registered";
|
private static final String PARTICIPANT_REGISTERED_TOPIC = "sample.participant.registered";
|
||||||
private static final String DISTRIBUTION_COMPLETED_TOPIC = "distribution.completed";
|
private static final String DISTRIBUTION_COMPLETED_TOPIC = "sample.distribution.completed";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
@ -33,9 +33,9 @@ public class DistributionCompletedConsumer {
|
|||||||
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DistributionCompleted 이벤트 처리
|
* DistributionCompleted 이벤트 처리 (MVP용 샘플 토픽)
|
||||||
*/
|
*/
|
||||||
@KafkaListener(topics = "distribution.completed", groupId = "analytics-service")
|
@KafkaListener(topics = "sample.distribution.completed", groupId = "analytics-service")
|
||||||
public void handleDistributionCompleted(String message) {
|
public void handleDistributionCompleted(String message) {
|
||||||
try {
|
try {
|
||||||
log.info("📩 DistributionCompleted 이벤트 수신: {}", message);
|
log.info("📩 DistributionCompleted 이벤트 수신: {}", message);
|
||||||
|
|||||||
@ -33,9 +33,9 @@ public class EventCreatedConsumer {
|
|||||||
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EventCreated 이벤트 처리
|
* EventCreated 이벤트 처리 (MVP용 샘플 토픽)
|
||||||
*/
|
*/
|
||||||
@KafkaListener(topics = "event.created", groupId = "analytics-service")
|
@KafkaListener(topics = "sample.event.created", groupId = "analytics-service")
|
||||||
public void handleEventCreated(String message) {
|
public void handleEventCreated(String message) {
|
||||||
try {
|
try {
|
||||||
log.info("📩 EventCreated 이벤트 수신: {}", message);
|
log.info("📩 EventCreated 이벤트 수신: {}", message);
|
||||||
|
|||||||
@ -33,9 +33,9 @@ public class ParticipantRegisteredConsumer {
|
|||||||
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
private static final long IDEMPOTENCY_TTL_DAYS = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParticipantRegistered 이벤트 처리
|
* ParticipantRegistered 이벤트 처리 (MVP용 샘플 토픽)
|
||||||
*/
|
*/
|
||||||
@KafkaListener(topics = "participant.registered", groupId = "analytics-service")
|
@KafkaListener(topics = "sample.participant.registered", groupId = "analytics-service")
|
||||||
public void handleParticipantRegistered(String message) {
|
public void handleParticipantRegistered(String message) {
|
||||||
try {
|
try {
|
||||||
log.info("📩 ParticipantRegistered 이벤트 수신: {}", message);
|
log.info("📩 ParticipantRegistered 이벤트 수신: {}", message);
|
||||||
|
|||||||
@ -51,6 +51,11 @@ spring:
|
|||||||
enable-auto-commit: true
|
enable-auto-commit: true
|
||||||
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||||
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||||
|
producer:
|
||||||
|
key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||||
|
value-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||||
|
acks: all
|
||||||
|
retries: 3
|
||||||
properties:
|
properties:
|
||||||
connections.max.idle.ms: 10000
|
connections.max.idle.ms: 10000
|
||||||
request.timeout.ms: 5000
|
request.timeout.ms: 5000
|
||||||
|
|||||||
63
tools/check-kafka-messages.ps1
Normal file
63
tools/check-kafka-messages.ps1
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Kafka 메시지 확인 스크립트 (Windows PowerShell)
|
||||||
|
#
|
||||||
|
# 사용법: .\check-kafka-messages.ps1
|
||||||
|
|
||||||
|
$KAFKA_SERVER = "4.230.50.63:9092"
|
||||||
|
|
||||||
|
Write-Host "========================================" -ForegroundColor Cyan
|
||||||
|
Write-Host "📊 Kafka 토픽 메시지 확인" -ForegroundColor Cyan
|
||||||
|
Write-Host "========================================" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# Kafka 설치 확인
|
||||||
|
$kafkaPath = Read-Host "Kafka 설치 경로를 입력하세요 (예: C:\kafka)"
|
||||||
|
|
||||||
|
if (-not (Test-Path "$kafkaPath\bin\windows\kafka-console-consumer.bat")) {
|
||||||
|
Write-Host "❌ Kafka가 해당 경로에 설치되어 있지 않습니다." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "✅ Kafka 경로 확인: $kafkaPath" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 토픽 선택
|
||||||
|
Write-Host "확인할 토픽을 선택하세요:" -ForegroundColor Yellow
|
||||||
|
Write-Host " 1. event.created (이벤트 생성)"
|
||||||
|
Write-Host " 2. participant.registered (참여자 등록)"
|
||||||
|
Write-Host " 3. distribution.completed (배포 완료)"
|
||||||
|
Write-Host " 4. 모두 확인"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$choice = Read-Host "선택 (1-4)"
|
||||||
|
|
||||||
|
$topics = @()
|
||||||
|
switch ($choice) {
|
||||||
|
"1" { $topics = @("event.created") }
|
||||||
|
"2" { $topics = @("participant.registered") }
|
||||||
|
"3" { $topics = @("distribution.completed") }
|
||||||
|
"4" { $topics = @("event.created", "participant.registered", "distribution.completed") }
|
||||||
|
default {
|
||||||
|
Write-Host "❌ 잘못된 선택입니다." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 각 토픽별 메시지 확인
|
||||||
|
foreach ($topic in $topics) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "========================================" -ForegroundColor Cyan
|
||||||
|
Write-Host "📩 토픽: $topic" -ForegroundColor Cyan
|
||||||
|
Write-Host "========================================" -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# 최근 5개 메시지만 확인
|
||||||
|
& "$kafkaPath\bin\windows\kafka-console-consumer.bat" `
|
||||||
|
--bootstrap-server $KAFKA_SERVER `
|
||||||
|
--topic $topic `
|
||||||
|
--from-beginning `
|
||||||
|
--max-messages 5 `
|
||||||
|
--timeout-ms 5000 2>&1 | Out-String | Write-Host
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "✅ 확인 완료!" -ForegroundColor Green
|
||||||
Loading…
x
Reference in New Issue
Block a user