-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jemin
committed
Jan 19, 2024
1 parent
9d324ff
commit 4aa9365
Showing
12 changed files
with
105 additions
and
126 deletions.
There are no files selected for viewing
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
2 changes: 0 additions & 2 deletions
2
src/main/java/com/backend/detailgoal/domain/repository/DetailGoalQueryRepository.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
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,29 @@ | ||
package com.backend.global.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; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig implements AsyncConfigurer { | ||
|
||
/* | ||
@Async를 사용할때 ThreadPoolTaskExecutor를 설정하지 않으면 쓰레드 1개로 동작합니다. | ||
따라서 쓰레드 풀을 할당해서 멀티 쓰레드로 동작하도록 만들었습니다. | ||
executor.setPrestartAllCoreThreads(false)로 설정해서 초반에 요청이 들어올때마다 CorePoolSize까지 쓰레드 개수를 늘리도록 만들었습니다. | ||
*/ | ||
@Override | ||
public Executor getAsyncExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(10); | ||
executor.setMaxPoolSize(10); | ||
executor.setQueueCapacity(1000); | ||
executor.setWaitForTasksToCompleteOnShutdown(true); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
} |
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
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: 0 additions & 31 deletions
31
src/main/java/com/backend/global/event/GoalEventHandler.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/main/java/com/backend/global/event/ReminderEventHandler.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/global/scheduler/SchedulerConstant.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,8 @@ | ||
package com.backend.global.scheduler; | ||
|
||
public abstract class SchedulerConstant { | ||
|
||
public static final String OUTDATED_GOAL_LOCK = "outdated_goal_lock"; | ||
public static final String SEND_ALARM_LOCK = "send_alarm_lock"; | ||
public static final String LOCAL_TIME_ZONE = "Asia/Seoul"; | ||
} |
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
37 changes: 15 additions & 22 deletions
37
src/main/java/com/backend/infrastructure/fcm/FcmService.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,55 +1,48 @@ | ||
package com.backend.infrastructure.fcm; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.backend.auth.application.FcmTokenService; | ||
import com.backend.global.exception.BusinessException; | ||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import com.google.firebase.messaging.FirebaseMessagingException; | ||
import com.google.firebase.messaging.Message; | ||
import com.google.firebase.messaging.Notification; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class FcmService { | ||
|
||
|
||
private final FcmTokenService fcmTokenService; | ||
|
||
private final FirebaseMessaging firebaseMessaging; | ||
|
||
public void sendMessage(String uid, String detailGoalTitle) | ||
{ | ||
public void sendMessage(String uid, String detailGoalTitle) { | ||
String fcmToken = fcmTokenService.findFcmToken(uid); | ||
|
||
if(Objects.isNull(fcmToken)) | ||
{ | ||
if (Objects.isNull(fcmToken)) { | ||
return; | ||
} | ||
|
||
Notification notification = Notification.builder() | ||
.setTitle(PushWord.PUSH_TITLE) | ||
.setBody(detailGoalTitle + PushWord.PUSH_CONTENT) | ||
.build(); | ||
.setTitle(PushWord.PUSH_TITLE) | ||
.setBody(detailGoalTitle + PushWord.PUSH_CONTENT) | ||
.build(); | ||
|
||
Message message = Message.builder() | ||
.setToken(fcmToken) | ||
.setNotification(notification) | ||
.build(); | ||
.setToken(fcmToken) | ||
.setNotification(notification) | ||
.build(); | ||
|
||
try { | ||
|
||
log.info("message send start..."); | ||
String send = firebaseMessaging.send(message); | ||
log.info("message send finished, {}", send); | ||
|
||
firebaseMessaging.send(message); | ||
} catch (FirebaseMessagingException e) { | ||
e.printStackTrace(); | ||
log.error(e.getMessage()); | ||
} | ||
} | ||
|
||
} |