Skip to content

Commit

Permalink
test: FCM 테스트
Browse files Browse the repository at this point in the history
- Client 확인을 위해 FCM Test 코드를 작성했습니다.
  • Loading branch information
HABINOH committed May 19, 2024
1 parent 124f231 commit a85bcfd
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions backEnd/src/main/java/com/quiz/ourclass/global/util/FcmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,38 @@ public Message makeMessage(String title, String body, String token) {
}

public void sendMessage(Message message) {
int attempt = 0;
long backoff = ConstantUtil.INITIAL_BACKOFF;

while (attempt < ConstantUtil.MAX_RETRIES) { //지수 백오프 전략
try {
FirebaseMessaging.getInstance().send(message);
log.info("FCM Send Success");
break; // 성공 시 루프 종료
} catch (FirebaseMessagingException e) {
log.error("FCM Send Error: {}", e.getMessage());
attempt++;
if (attempt >= ConstantUtil.MAX_RETRIES) {
// 최대 재시도 횟수 도달 시 루프 종료
// 다른 메시지 시스템으로 알림을 전송하는 방법을 고려해볼 수 있음
log.error("Reached Maximum Retry Attempts");
break;
}
try {
Thread.sleep(backoff); // 지수 백오프를 위한 대기
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
log.error("Interrupted While Waiting For Retry");
break; // 인터럽트 발생 시 루프 종료
}
backoff *= 2;
}
try {
FirebaseMessaging.getInstance().send(message);
} catch (FirebaseMessagingException e) {
log.error("fcm send error");
}
// int attempt = 0;
// long backoff = ConstantUtil.INITIAL_BACKOFF;
//
// while (attempt < ConstantUtil.MAX_RETRIES) { //지수 백오프 전략
// try {
// FirebaseMessaging.getInstance().send(message);
// log.info("FCM Send Success");
// break; // 성공 시 루프 종료
// } catch (FirebaseMessagingException e) {
// log.error("FCM Send Error: {}", e.getMessage());
// attempt++;
// if (attempt >= ConstantUtil.MAX_RETRIES) {
// // 최대 재시도 횟수 도달 시 루프 종료
// // 다른 메시지 시스템으로 알림을 전송하는 방법을 고려해볼 수 있음
// log.error("Reached Maximum Retry Attempts");
// break;
// }
// try {
// Thread.sleep(backoff); // 지수 백오프를 위한 대기
// } catch (InterruptedException ie) {
// Thread.currentThread().interrupt();
// log.error("Interrupted While Waiting For Retry");
// break; // 인터럽트 발생 시 루프 종료
// }
// backoff *= 2;
// }
// }
}

public FcmDTO makeFcmDTO(String title, String body) {
Expand Down

0 comments on commit a85bcfd

Please sign in to comment.