Skip to content

Commit 7a57922

Browse files
committed
refactor: 컨슈머 로직 수정
1 parent 6ec8faa commit 7a57922

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/org/ezcode/codetest/infrastructure/event/config/RedisStreamConfig.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.UnknownHostException;
55
import java.time.Duration;
66
import java.util.Map;
7+
import java.util.UUID;
78
import java.util.concurrent.Executor;
89

910
import org.ezcode.codetest.infrastructure.event.listener.RedisJudgeQueueConsumer;
@@ -52,7 +53,7 @@ public void initConsumerGroup() {
5253
connection.xGroupDelConsumer(
5354
"judge-queue".getBytes(),
5455
"judge-group",
55-
"consumer-1"
56+
getConsumerName().replace("consumer-", "")
5657
);
5758
return null;
5859
});
@@ -78,7 +79,7 @@ public void initConsumerGroup() {
7879
public StreamMessageListenerContainer<String, MapRecord<String, String, String>> streamMessageListenerContainer(
7980
RedisConnectionFactory factory,
8081
RedisJudgeQueueConsumer consumer
81-
) throws UnknownHostException {
82+
) {
8283
StreamMessageListenerContainer
8384
.StreamMessageListenerContainerOptions<String, MapRecord<String, String, String>> options =
8485
StreamMessageListenerContainer
@@ -92,12 +93,21 @@ public StreamMessageListenerContainer<String, MapRecord<String, String, String>>
9293
StreamMessageListenerContainer.create(factory, options);
9394

9495
container.receive(
95-
Consumer.from("judge-group", "consumer-" + InetAddress.getLocalHost().getHostName()),
96+
Consumer.from("judge-group", getConsumerName()),
9697
StreamOffset.create("judge-queue", ReadOffset.lastConsumed()),
9798
consumer
9899
);
99100

100101
container.start();
101102
return container;
102103
}
104+
105+
private String getConsumerName() {
106+
try {
107+
return "consumer-" + InetAddress.getLocalHost().getHostName();
108+
} catch (UnknownHostException e) {
109+
log.warn("호스트명 확인 실패, UUID 사용: {}", e.getMessage());
110+
return "consumer-" + UUID.randomUUID().toString().substring(0, 8);
111+
}
112+
}
103113
}

0 commit comments

Comments
 (0)