Skip to content

Commit 65e05fd

Browse files
authored
feat: 카카오 로그인 재시도 로직, 방 참가자 관리 동시성 수정 (#91)
* feat: restTemplate 재시도 로직 추가 * feat: 방 참가자 관리 동시성 수정 및 비밀코드 방 참가 수정
1 parent 12c801a commit 65e05fd

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dependencies {
6363
// caffeine
6464
implementation 'com.github.ben-manes.caffeine:caffeine'
6565

66+
implementation 'org.springframework.retry:spring-retry:2.0.12'
6667
}
6768

6869
tasks.named('test') {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.oronaminc.join.global.config;
2+
3+
import java.time.Duration;
4+
5+
import org.springframework.boot.web.client.RestTemplateBuilder;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.http.client.ClientHttpRequestInterceptor;
9+
import org.springframework.retry.policy.SimpleRetryPolicy;
10+
import org.springframework.retry.support.RetryTemplate;
11+
import org.springframework.web.client.RestTemplate;
12+
13+
@Configuration
14+
class RestTemplateConfig {
15+
16+
@Bean
17+
public RestTemplate restTemplate() {
18+
return new RestTemplateBuilder()
19+
.connectTimeout(Duration.ofSeconds(5))
20+
.readTimeout(Duration.ofSeconds(5))
21+
.additionalInterceptors(clientHttpRequestInterceptor())
22+
.build();
23+
}
24+
25+
// 3번 재시도
26+
public ClientHttpRequestInterceptor clientHttpRequestInterceptor() {
27+
return (request, body, execution) -> {
28+
RetryTemplate retryTemplate = new RetryTemplate();
29+
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3));
30+
try {
31+
return retryTemplate.execute(context -> execution.execute(request, body));
32+
} catch (Throwable throwable) {
33+
throw new RuntimeException(throwable);
34+
}
35+
};
36+
}
37+
38+
}

src/main/java/com/oronaminc/join/room/api/RoomController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public CreateRoomResponse createRoom(
6363
description = "비밀코드를 통해 해당 발표방에 참가자로 등록합니다. 시작 전 상태이면 참가할 수 없습니다.",
6464
security = @SecurityRequirement(name = "sessionAuth")
6565
)
66-
@GetMapping("/code")
66+
@PostMapping("/code")
6767
@ResponseStatus(HttpStatus.OK)
6868
public JoinRoomResponse joinRoom(
6969
@RequestBody JoinRoomRequest joinRoomRequest,

src/main/java/com/oronaminc/join/websocket/session/CurrentParticipantManager.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,36 @@ public void createRoom(Long roomId) {
2323
roomParticipants.computeIfAbsent(roomId, k -> ConcurrentHashMap.newKeySet());
2424
}
2525

26+
// public void addParticipant(Long roomId, Long memberId, int limit) {
27+
// Set<Long> participants = getRoomParticipants(roomId);
28+
//
29+
// if (participants.contains(memberId)) return;
30+
//
31+
// synchronized (participants) {
32+
// if (participants.size() >= limit) {
33+
// throw new ErrorException(UNAUTHORIZED_LIMIT_PARTICIPANT);
34+
// }
35+
// participants.add(memberId);
36+
// }
37+
// }
38+
2639
public void addParticipant(Long roomId, Long memberId, int limit) {
27-
Set<Long> participants = getRoomParticipants(roomId);
40+
roomParticipants.compute(roomId, (id, participants) -> {
41+
participants = getRoomParticipants(roomId);
2842

29-
if (participants.contains(memberId)) return;
43+
// 중복 참가자일 경우 그대로 반환 (변화 없음)
44+
if (participants.contains(memberId)) {
45+
return participants;
46+
}
3047

31-
synchronized (participants) {
48+
// 인원 초과 시 예외 발생
3249
if (participants.size() >= limit) {
3350
throw new ErrorException(UNAUTHORIZED_LIMIT_PARTICIPANT);
3451
}
52+
3553
participants.add(memberId);
36-
}
54+
return participants;
55+
});
3756
}
3857

3958
public void removeParticipant(Long memberId, Long roomId) {

0 commit comments

Comments
 (0)