From c1d4c1ff1d99798d3bc7300ee9f37b1ee2dde8a8 Mon Sep 17 00:00:00 2001 From: Klaus Date: Tue, 22 Apr 2025 17:44:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B8=B0=EC=A1=B4=20=ED=91=B8=EC=8B=9C?= =?UTF-8?q?=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=97=90=20=EC=B5=9C=EB=8C=80=203=ED=9A=8C=20?= =?UTF-8?q?=EC=9E=AC=EC=8B=9C=EB=8F=84=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/vividnext/sodalive/fcm/FcmService.kt | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt index 1f96de1..7a51f63 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmService.kt @@ -29,8 +29,14 @@ class FcmService { creatorId: Long? = null, auditionId: Long? = null ) { - if (tokens.isNotEmpty()) { - logger.info("os: $container") + if (tokens.isEmpty()) return + logger.info("os: $container") + + var targets = tokens + val maxAttempts = 3 + var attempt = 1 + + while (attempt <= maxAttempts && targets.isNotEmpty()) { val multicastMessage = MulticastMessage.builder() .addAllTokens(tokens) @@ -85,8 +91,34 @@ class FcmService { } val response = FirebaseMessaging.getInstance().sendEachForMulticast(multicastMessage.build()) - logger.info("[FCM] ✅ 성공: ${response.successCount}") - logger.info("[FCM] ❌ 실패: ${response.failureCount}") + val failedTokens = mutableListOf() + + response.responses.forEachIndexed { index, res -> + if (!res.isSuccessful) { + val exception = res.exception + val token = targets[index] + + if (exception?.messagingErrorCode == MessagingErrorCode.UNREGISTERED) { + logger.error("[FCM] ❌ UNREGISTERED → $token") + // 필요 시 DB에서 삭제 + } else { + logger.error("[FCM] ❌ 실패: $token / ${exception?.messagingErrorCode}") + failedTokens.add(token) + } + } + } + + if (failedTokens.isEmpty()) { + logger.info("[FCM] ✅ 전체 전송 성공") + return + } + + targets = failedTokens + attempt++ + } + + if (targets.isNotEmpty()) { + logger.error("[FCM] ❌ 최종 실패 대상 ${targets.size}명 → $targets") } }