-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: 알림 기능 로직 개선 및 알림 테스트 추가 #497
Merged
The head ref may contain hidden characters: "test/490-\uC54C\uB9BC_\uD14C\uC2A4\uD2B8_\uB85C\uC9C1_\uAC1C\uC120"
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
7482a31
test: 테스트용 api 수정 및 추가
Kim0914 bea9ea6
test: @EnableAsync 어노테이션 추가
Kim0914 ffe1549
test: 알림 이벤트 로그 정보 추가
Kim0914 4a5082f
test: 미사용 테스트 api 주석 처리
Kim0914 a22ec60
refactor: Async ThreadExecutor 설정 변경
Kim0914 47dc133
refactor: 불필요한 트랜잭션 설정 제거
Kim0914 68644df
refactor: Async ThreadPool 설정 수정
Kim0914 c6d8f44
refactor: Async ThreadPool 설정 30 수정
Kim0914 8472a4a
refactor: Async ThreadPool 설정 20 수정
Kim0914 cdcb3c2
refactor: Async ThreadPool 설정 40 수정
Kim0914 0b3b9c8
refactor: Async ThreadPool 설정 20 수정
Kim0914 9fc3d3d
refactor: Async ThreadPool 설정 30 수정
Kim0914 6478813
refactor: Async ThreadPool 설정 40 수정
Kim0914 8630a23
refactor: Async ThreadPool 램프업 스레드 수 변경
Kim0914 5604c11
refactor: Async ThreadPool 스레드 수 변경
Kim0914 9fd8651
refactor: Async ThreadPool 스레드 수 변경
Kim0914 b615b8b
refactor: Async ThreadPool 스레드 수 변경
Kim0914 597f09a
refactor: Async ThreadPool 스레드 수 변경
Kim0914 3db6b51
refactor: Async ThreadPool 스레드 수 변경
Kim0914 e28bad0
refactor: Async ThreadPool 스레드 수 30으로 변경
Kim0914 89435a4
refactor: Async ThreadPool 스레드 수 50으로 변경
Kim0914 95cc8e6
refactor: Async ThreadPool 스레드 수 40으로 변경
Kim0914 659ca56
refactor: Async ThreadPool 스레드 수 30으로 변경
Kim0914 1a13090
refactor: Async ThreadPool 스레드 수 100으로 변경
Kim0914 eb10b0c
refactor: Async ThreadPool 스레드 수 8으로 변경
Kim0914 33d1c88
refactor: Async 테스트 설정 변경
Kim0914 9544240
refactor: Async 테스트 스레드 풀 설정 15로 변경
Kim0914 81d17c3
refactor: Async 테스트 스레드 풀 설정 15로 변경
Kim0914 e437712
refactor: Async 테스트 스레드 풀 설정 25로 변경
Kim0914 63422eb
refactor: 램프 코드 반복 횟수 변경
Kim0914 837d2e1
refactor: 알림 허용 시 알림 발송 로직 추가
Kim0914 f2a1e6e
refactor: Async thread 30으로 변경
Kim0914 7def1fb
refactor: Async thread 35으로 변경
Kim0914 0db6553
refactor: Async thread 45으로 변경
Kim0914 c5e2efe
refactor: Async thread 50으로 변경
Kim0914 75d17e2
refactor: Async thread 40으로 변경
Kim0914 01c06a8
refactor: Async thread 50으로 변경
Kim0914 fcd29a3
test: 알림 구독 시 알림 발송 이벤트 테스트 추가
Kim0914 2b1b2cf
test: 알림 전송 메서드 테스트 추가
Kim0914 d2defe0
refactor: 알림 발송 로직 변경
Kim0914 3e8c068
test: 알림 이벤트 리스너 테스트 추가
Kim0914 0bee745
chore: 테스트 컨트롤러 비활성화
Kim0914 3724a82
chore: 비동기 스레드 풀 코어 수 40으로 설정
Kim0914 9fd8bdf
chore: 불필요한 주석 제거
Kim0914 a69624d
refactor: 사용하지 않는 이벤트 리스너 및 이벤트 객체 삭제
Kim0914 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
backend/pium/src/main/java/com/official/pium/admin/service/TestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.official.pium.admin.service; | ||
|
||
import com.official.pium.petPlant.domain.PetPlant; | ||
import com.official.pium.petPlant.event.notification.NotificationEvent; | ||
import com.official.pium.petPlant.repository.PetPlantRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TestService { | ||
|
||
private final PetPlantRepository petPlantRepository; | ||
private final ApplicationEventPublisher publisher; | ||
|
||
// public void sendWaterNotificationTest() { | ||
// List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L); | ||
// List<NotificationEvent> events = petPlants.stream() | ||
// .map(plant -> NotificationEvent.builder() | ||
// .title(plant.getNickname()) | ||
// .body("(테스트 중) 물을 줄 시간이에요!") | ||
// .deviceToken(plant.getMember().getDeviceToken()) | ||
// .build() | ||
// ).toList(); | ||
// log.info("동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
// publisher.publishEvent(NotificationEvents.from(events)); | ||
// log.info("동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
// } | ||
|
||
public void sendWaterNotificationAsyncRampTest() { | ||
List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(6L); | ||
// List<NotificationEvent> events = petPlants.stream() | ||
// .map(plant -> NotificationEvent.builder() | ||
// .title(plant.getNickname()) | ||
// .body("(테스트 중) 물을 줄 시간이에요!") | ||
// .deviceToken(plant.getMember().getDeviceToken()) | ||
// .build() | ||
// ).toList(); | ||
|
||
for (int i = 0; i < 100; i++) { | ||
PetPlant petPlant = petPlants.get(i); | ||
NotificationEvent event = NotificationEvent.builder() | ||
.title(petPlant.getNickname()) | ||
.body("물줘") | ||
.deviceToken(petPlant.getMember().getDeviceToken()) | ||
.build(); | ||
publisher.publishEvent(event); | ||
} | ||
|
||
// log.info("비동기 테스트 램프업 시작"); | ||
// for (int i = 0; i < 100; i++) { | ||
// NotificationEvent notificationEvent = events.get(i); | ||
// publisher.publishEvent(notificationEvent); | ||
// } | ||
} | ||
|
||
public void sendWaterNotificationAsyncTest() { | ||
List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(6L); | ||
List<NotificationEvent> events = petPlants.stream() | ||
.map(plant -> NotificationEvent.builder() | ||
.title(plant.getNickname()) | ||
.body("(테스트 중) 물을 줄 시간이에요!") | ||
.deviceToken(plant.getMember().getDeviceToken()) | ||
.build() | ||
).toList(); | ||
|
||
int i = 1; | ||
log.info("비동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
for (NotificationEvent event : events) { | ||
log.info(i++ + "번째 알림 이벤트"); | ||
publisher.publishEvent(event); | ||
} | ||
log.info("비동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/pium/src/main/java/com/official/pium/admin/ui/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.official.pium.admin.ui; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/test") | ||
public class TestController { | ||
|
||
// private final TestService testService; | ||
|
||
// @GetMapping("/notifications") | ||
// public ResponseEntity<String> notificationTest() { | ||
// testService.sendWaterNotificationTest(); | ||
// return ResponseEntity.ok("알림 기능 테스트 성공"); | ||
// } | ||
|
||
// @GetMapping("/notifications/ramp") | ||
// public ResponseEntity<String> notificationRampTest() { | ||
// testService.sendWaterNotificationAsyncRampTest(); | ||
// return ResponseEntity.ok("비동기 알림 기능 테스트 램프업 성공"); | ||
// } | ||
// | ||
// @GetMapping("/notifications/async") | ||
// public ResponseEntity<String> notificationAsyncTest() { | ||
// testService.sendWaterNotificationAsyncTest(); | ||
// return ResponseEntity.ok("비동기 알림 기능 테스트 성공"); | ||
// } | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/pium/src/main/java/com/official/pium/config/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.official.pium.config; | ||
|
||
import java.util.concurrent.Executor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncConfig implements AsyncConfigurer { | ||
|
||
@Override | ||
public Executor getAsyncExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(40); | ||
executor.setThreadNamePrefix("2024-Pium-Thread: "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A디버깅할때 용이하겠군요 👍 |
||
executor.initialize(); | ||
return executor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
...m/src/main/java/com/official/pium/notification/application/NotificationEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
package com.official.pium.notification.application; | ||
|
||
import com.official.pium.petPlant.event.notification.NotificationEvent; | ||
import com.official.pium.petPlant.event.notification.NotificationEvents; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class NotificationEventListener { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@EventListener | ||
@Async | ||
public void handleNotificationEvents(NotificationEvents notificationEvents) { | ||
for (NotificationEvent event : notificationEvents.getNotificationEvents()) { | ||
notificationService.sendNotification(event.getDeviceToken(), event.getTitle(), event.getBody()); | ||
} | ||
public void handleNotificationEvent(NotificationEvent event) { | ||
log.info("비동기 알림 START, Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
notificationService.sendNotification(event.getDeviceToken(), event.getTitle(), event.getBody()); | ||
log.info("비동기 알림 END, Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
.../pium/src/main/java/com/official/pium/petPlant/event/notification/NotificationEvents.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
오 비동기 설정을 별도로 분리했군요! 👍