From 1d69852e2ecd1e53466a9d752778927bbea30b9c Mon Sep 17 00:00:00 2001 From: MiN <81948815+leesumin0526@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:07:39 +1000 Subject: [PATCH] =?UTF-8?q?[REFACTOR/#181]=20-=20RabbitMQ=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationListener.java | 26 ++++++------------- src/main/resources/application.yml | 16 ++++++------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/assu/server/domain/notification/service/NotificationListener.java b/src/main/java/com/assu/server/domain/notification/service/NotificationListener.java index 07e19738..841f8964 100644 --- a/src/main/java/com/assu/server/domain/notification/service/NotificationListener.java +++ b/src/main/java/com/assu/server/domain/notification/service/NotificationListener.java @@ -23,28 +23,19 @@ public class NotificationListener { private final FcmClient fcmClient; private final OutboxStatusService outboxStatus; // ← 주입 - @RabbitListener(queues = AmqpConfig.QUEUE) + @RabbitListener(queues = AmqpConfig.QUEUE, ackMode = "MANUAL") public void onMessage(@Payload NotificationMessageDTO payload, Channel ch, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws Exception { try { - fcmClient.sendToMemberId( - payload.getReceiverId(), - payload.getTitle(), - payload.getBody(), - payload.getData() - ); - ch.basicAck(tag, false); - - // idempotencyKey = outboxId 로 보냈으니 그대로 사용 + fcmClient.sendToMemberId(payload.getReceiverId(), payload.getTitle(), payload.getBody(), payload.getData()); Long outboxId = Long.valueOf(payload.getIdempotencyKey()); - outboxStatus.markSent(outboxId); // 새 트랜잭션에서 SENT 전이 + outboxStatus.markSent(outboxId); // ★ ACK 전에 완료 표시 + + ch.basicAck(tag, false); // ★ 맨 마지막에 단 한 번만 ACK } catch (RuntimeException e) { - if (isTransient(e)) { - ch.basicNack(tag, false, true); - } else { - ch.basicNack(tag, false, false); - } + if (isTransient(e)) ch.basicNack(tag, false, true); + else ch.basicNack(tag, false, false); } catch (Exception e) { ch.basicNack(tag, false, false); } @@ -61,5 +52,4 @@ private boolean isTransient(Throwable t) { } return false; } -} - +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 61918f57..4c103422 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,14 +19,14 @@ spring: highlight_sql : true lifecycle: timeout-per-shutdown-phase: 30s - rabbitmq: - listener: - simple: - acknowledge-mode: manual - prefetch: 20 - concurrency: 1 - max-concurrency: 4 - default-requeue-rejected: false + rabbitmq: + listener: + simple: + acknowledge-mode: manual + prefetch: 20 + concurrency: 1 + max-concurrency: 4 + default-requeue-rejected: false logging: level: