Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -61,5 +52,4 @@ private boolean isTransient(Throwable t) {
}
return false;
}
}

}
16 changes: 8 additions & 8 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down