From c1e2b7d273d6491e8d01ba985f36edf9588f13e8 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Thu, 8 Aug 2024 12:51:05 +0900 Subject: [PATCH 01/14] =?UTF-8?q?fix=20:=20=EC=93=B8=EB=AA=A8=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=B0=8F=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CapsuleSkinNotificationSendRequest.java | 28 -------- .../request/FriendNotificationRequest.java | 22 ------- .../global/error/ErrorResponse.java | 20 ------ .../global/error/GlobalExceptionHandler.java | 66 ------------------- ...cmMessageData.java => FCMMessageData.java} | 4 +- .../CapsuleSkinFcmManagerImpl.java | 14 ++-- .../fcm/friend/FriendFcmManagerImpl.java | 21 +++--- .../infra/fcm/group/GroupFcmManagerImpl.java | 22 +++---- 8 files changed, 27 insertions(+), 170 deletions(-) delete mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java delete mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/FriendNotificationRequest.java delete mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/ErrorResponse.java delete mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/GlobalExceptionHandler.java rename backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/{FcmMessageData.java => FCMMessageData.java} (82%) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java deleted file mode 100644 index cbad10cd3..000000000 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java +++ /dev/null @@ -1,28 +0,0 @@ -package site.timecapsulearchive.notification.data.request; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import site.timecapsulearchive.notification.entity.NotificationStatus; - -public record CapsuleSkinNotificationSendRequest( - - @NotNull(message = "멤버 아이디는 필수 입니다.") - Long memberId, - - @NotNull(message = "알림 상태는 필수 입니다.") - NotificationStatus status, - - @NotBlank(message = "스킨 이름은 필수 입니다.") - String skinName, - - @NotBlank(message = "알림 내용은 필수 입니다.") - String title, - - @NotBlank(message = "알림 내용은 필수 입니다.") - String text, - - @NotBlank(message = "스킨 URL은 필수 입니다.") - String skinUrl -) { - -} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/FriendNotificationRequest.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/FriendNotificationRequest.java deleted file mode 100644 index 44956bcd7..000000000 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/FriendNotificationRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -package site.timecapsulearchive.notification.data.request; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import site.timecapsulearchive.notification.entity.NotificationStatus; - -public record FriendNotificationRequest( - - @NotNull(message = "멤버 아이디는 필수 입니다.") - Long targetId, - - @NotNull(message = "알림 상태는 필수 입니다.") - NotificationStatus status, - - @NotBlank(message = "알림 제목은 필수 입니다.") - String text, - - @NotBlank(message = "알림 내용은 필수 입니다.") - String title -) { - -} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/ErrorResponse.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/ErrorResponse.java deleted file mode 100644 index a38fa9886..000000000 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/ErrorResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package site.timecapsulearchive.notification.global.error; - -public record ErrorResponse(String message) { - - public static ErrorResponse httpMessageNotReadable() { - return new ErrorResponse("요청 메시지를 읽을 수 없습니다."); - } - - public static ErrorResponse messageNotSendable() { - return new ErrorResponse("메시지를 보낼 수 없습니다."); - } - - public static ErrorResponse methodArgumentNotValid() { - return new ErrorResponse("타당하지 않은 요청 인자 입니다."); - } - - public static ErrorResponse exception() { - return new ErrorResponse("서버에 에러가 발생하였습니다."); - } -} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/GlobalExceptionHandler.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/GlobalExceptionHandler.java deleted file mode 100644 index 619b1cd0a..000000000 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/GlobalExceptionHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -package site.timecapsulearchive.notification.global.error; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; - -@RestControllerAdvice -@Slf4j -public class GlobalExceptionHandler { - - @ExceptionHandler(Exception.class) - protected ResponseEntity handleGlobalException(final Exception e) { - log.error(e.getMessage(), e); - final ErrorResponse errorResponse = ErrorResponse.exception(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(errorResponse); - } - - @ExceptionHandler(MessageNotSendAbleException.class) - protected ResponseEntity handleMessageNotSendableException( - final MessageNotSendAbleException e) { - log.warn(e.getMessage(), e); - - final ErrorResponse errorResponse = ErrorResponse.messageNotSendable(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(errorResponse); - } - - @ExceptionHandler(MethodArgumentNotValidException.class) - protected ResponseEntity handleRequestArgumentNotValidException( - MethodArgumentNotValidException e - ) { - log.warn(e.getMessage(), e); - - final ErrorResponse errorResponse = ErrorResponse.methodArgumentNotValid(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(errorResponse); - } - - @ExceptionHandler(HttpMessageNotReadableException.class) - protected ResponseEntity handleRequestTypeNotValidException( - HttpMessageNotReadableException e - ) { - log.warn(e.getMessage(), e); - - final ErrorResponse response = ErrorResponse.httpMessageNotReadable(); - return ResponseEntity.status(HttpStatus.BAD_REQUEST) - .body(response); - } - - @ExceptionHandler(InternalServerException.class) - protected ResponseEntity handleInternalServerException( - InternalServerException e - ) { - log.error(e.getMessage(), e); - - final ErrorResponse errorResponse = ErrorResponse.exception(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(errorResponse); - } -} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FcmMessageData.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMMessageData.java similarity index 82% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FcmMessageData.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMMessageData.java index c979c8aa0..adcb64c60 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FcmMessageData.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMMessageData.java @@ -1,6 +1,6 @@ package site.timecapsulearchive.notification.infra.fcm; -public enum FcmMessageData { +public enum FCMMessageData { TOPIC("topic"), STATUS("status"), @@ -11,7 +11,7 @@ public enum FcmMessageData { private final String data; - FcmMessageData(String data) { + FCMMessageData(String data) { this.data = data; } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java index fa4cdbe61..6803983df 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java @@ -8,15 +8,13 @@ import site.timecapsulearchive.notification.data.dto.CapsuleSkinNotificationSendDto; import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; -import site.timecapsulearchive.notification.infra.fcm.FCMManager; -import site.timecapsulearchive.notification.infra.fcm.FcmMessageData; +import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; @Component @RequiredArgsConstructor public class CapsuleSkinFcmManagerImpl implements CapsuleSkinFcmManager { - private final FCMManager fcmManager; private final S3PreSignedUrlManager s3PreSignedUrlManager; public void sendCapsuleSkinNotification( @@ -28,12 +26,12 @@ public void sendCapsuleSkinNotification( FirebaseMessaging.getInstance() .send( Message.builder() - .putData(FcmMessageData.TOPIC.getData(), String.valueOf(categoryName)) - .putData(FcmMessageData.STATUS.getData(), String.valueOf(dto.status())) - .putData(FcmMessageData.TITLE.getData(), dto.title()) - .putData(FcmMessageData.TEXT.getData(), dto.text()) + .putData(FCMMessageData.TOPIC.getData(), String.valueOf(categoryName)) + .putData(FCMMessageData.STATUS.getData(), String.valueOf(dto.status())) + .putData(FCMMessageData.TITLE.getData(), dto.title()) + .putData(FCMMessageData.TEXT.getData(), dto.text()) .setToken(fcmToken) - .putData(FcmMessageData.IMAGE.getData(), + .putData(FCMMessageData.IMAGE.getData(), s3PreSignedUrlManager.createS3PreSignedUrlForGet(dto.skinUrl())) .build() ); diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java index ff88e1599..d3c8e60c4 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java @@ -11,15 +11,12 @@ import site.timecapsulearchive.notification.data.dto.FriendNotificationsDto; import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; -import site.timecapsulearchive.notification.infra.fcm.FCMManager; -import site.timecapsulearchive.notification.infra.fcm.FcmMessageData; +import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; @Component @RequiredArgsConstructor public class FriendFcmManagerImpl implements FriendFcmManager { - private final FCMManager fcmManager; - public void sendFriendNotification( final FriendNotificationDto dto, final CategoryName categoryName, @@ -29,11 +26,11 @@ public void sendFriendNotification( FirebaseMessaging.getInstance() .send( Message.builder() - .putData(FcmMessageData.TOPIC.getData(), String.valueOf(categoryName)) - .putData(FcmMessageData.STATUS.getData(), + .putData(FCMMessageData.TOPIC.getData(), String.valueOf(categoryName)) + .putData(FCMMessageData.STATUS.getData(), String.valueOf(dto.notificationStatus())) - .putData(FcmMessageData.TITLE.getData(), dto.title()) - .putData(FcmMessageData.TEXT.getData(), dto.text()) + .putData(FCMMessageData.TITLE.getData(), dto.title()) + .putData(FCMMessageData.TEXT.getData(), dto.text()) .setToken(fcmToken) .build() ); @@ -52,11 +49,11 @@ public void sendFriendNotifications( .sendEachForMulticast( MulticastMessage.builder() .addAllTokens(fcmTokens) - .putData(FcmMessageData.TOPIC.getData(), String.valueOf(categoryName)) - .putData(FcmMessageData.STATUS.getData(), + .putData(FCMMessageData.TOPIC.getData(), String.valueOf(categoryName)) + .putData(FCMMessageData.STATUS.getData(), String.valueOf(dto.notificationStatus())) - .putData(FcmMessageData.TITLE.getData(), dto.title()) - .putData(FcmMessageData.TEXT.getData(), dto.text()) + .putData(FCMMessageData.TITLE.getData(), dto.title()) + .putData(FCMMessageData.TEXT.getData(), dto.text()) .build() ); } catch (FirebaseMessagingException exception) { diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java index 86123f416..92f19f479 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java @@ -11,15 +11,13 @@ import site.timecapsulearchive.notification.data.dto.GroupInviteNotificationDto; import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; -import site.timecapsulearchive.notification.infra.fcm.FCMManager; -import site.timecapsulearchive.notification.infra.fcm.FcmMessageData; +import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; @Component @RequiredArgsConstructor public class GroupFcmManagerImpl implements GroupFcmManager { - private final FCMManager fcmManager; private final S3PreSignedUrlManager s3PreSignedUrlManager; public void sendGroupInviteNotifications( @@ -32,12 +30,12 @@ public void sendGroupInviteNotifications( .sendEachForMulticast( MulticastMessage.builder() .addAllTokens(fcmTokens) - .putData(FcmMessageData.TOPIC.getData(), String.valueOf(categoryName)) - .putData(FcmMessageData.STATUS.getData(), + .putData(FCMMessageData.TOPIC.getData(), String.valueOf(categoryName)) + .putData(FCMMessageData.STATUS.getData(), String.valueOf(dto.notificationStatus())) - .putData(FcmMessageData.TITLE.getData(), dto.title()) - .putData(FcmMessageData.TEXT.getData(), dto.text()) - .putData(FcmMessageData.IMAGE.getData(), + .putData(FCMMessageData.TITLE.getData(), dto.title()) + .putData(FCMMessageData.TEXT.getData(), dto.text()) + .putData(FCMMessageData.IMAGE.getData(), s3PreSignedUrlManager.createS3PreSignedUrlForGet(dto.groupProfileUrl())) .build() ); @@ -55,11 +53,11 @@ public void sendGroupAcceptNotification( FirebaseMessaging.getInstance() .send( Message.builder() - .putData(FcmMessageData.TOPIC.getData(), String.valueOf(categoryName)) - .putData(FcmMessageData.STATUS.getData(), + .putData(FCMMessageData.TOPIC.getData(), String.valueOf(categoryName)) + .putData(FCMMessageData.STATUS.getData(), String.valueOf(dto.notificationStatus())) - .putData(FcmMessageData.TITLE.getData(), dto.title()) - .putData(FcmMessageData.TEXT.getData(), dto.text()) + .putData(FCMMessageData.TITLE.getData(), dto.title()) + .putData(FCMMessageData.TEXT.getData(), dto.text()) .setToken(fcmToken) .build() ); From 51146f16a1210debbb532861cea057a926eca9a8 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Thu, 8 Aug 2024 13:28:23 +0900 Subject: [PATCH 02/14] =?UTF-8?q?feat=20:=20aop=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EB=A1=9C=EA=B9=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/aop/LoggingComponent.java | 20 +++++++++++++++++++ .../notification/global/aop/Trace.java | 11 ++++++++++ .../notification/infra/fcm/FCMManager.java | 4 ++++ .../CapsuleSkinFcmManagerImpl.java | 2 ++ .../fcm/friend/FriendFcmManagerImpl.java | 3 +++ .../infra/fcm/group/GroupFcmManagerImpl.java | 3 +++ .../repository/member/MemberRepository.java | 3 +++ .../NotificationQueryRepositoryImpl.java | 2 ++ .../capsuleskin/CapsuleSkinAlarmService.java | 5 ++--- .../service/friend/FriendAlarmService.java | 9 +++++++-- .../service/group/GroupAlarmService.java | 5 ++++- .../src/main/resources/logback-spring.xml | 4 ++-- 12 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java create mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java new file mode 100644 index 000000000..cab14c4e7 --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java @@ -0,0 +1,20 @@ +package site.timecapsulearchive.notification.global.aop; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.stereotype.Component; + +@Slf4j +@Aspect +@Component +public class LoggingComponent { + + @Before("@annotation(site.timecapsulearchive.notification.global.aop.Trace)") + public void doTrace(JoinPoint joinPoint) { + Object[] args = joinPoint.getArgs(); + + log.info("{} args={}", joinPoint.getSignature(), args); + } +} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java new file mode 100644 index 000000000..fca893927 --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java @@ -0,0 +1,11 @@ +package site.timecapsulearchive.notification.global.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Trace { +} \ No newline at end of file diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java index e409db1ae..ec617448d 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java @@ -7,9 +7,11 @@ import java.io.IOException; import java.io.InputStream; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; +@Slf4j @Component @RequiredArgsConstructor public class FCMManager { @@ -18,12 +20,14 @@ public class FCMManager { @PostConstruct public void initialize() throws IOException { + log.info("fcm manager 초기화 시작"); FirebaseOptions options = FirebaseOptions.builder() .setCredentials(GoogleCredentials.fromStream(getCredential())) .setProjectId(fcmProperties.projectId()) .build(); FirebaseApp.initializeApp(options); + log.info("fcm manager 초기화 완료"); } private InputStream getCredential() throws IOException { diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java index 6803983df..95c91cc0e 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Component; import site.timecapsulearchive.notification.data.dto.CapsuleSkinNotificationSendDto; import site.timecapsulearchive.notification.entity.CategoryName; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; @@ -17,6 +18,7 @@ public class CapsuleSkinFcmManagerImpl implements CapsuleSkinFcmManager { private final S3PreSignedUrlManager s3PreSignedUrlManager; + @Trace public void sendCapsuleSkinNotification( final CapsuleSkinNotificationSendDto dto, final CategoryName categoryName, diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java index d3c8e60c4..9752f2602 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java @@ -10,6 +10,7 @@ import site.timecapsulearchive.notification.data.dto.FriendNotificationDto; import site.timecapsulearchive.notification.data.dto.FriendNotificationsDto; import site.timecapsulearchive.notification.entity.CategoryName; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; @@ -17,6 +18,7 @@ @RequiredArgsConstructor public class FriendFcmManagerImpl implements FriendFcmManager { + @Trace public void sendFriendNotification( final FriendNotificationDto dto, final CategoryName categoryName, @@ -39,6 +41,7 @@ public void sendFriendNotification( } } + @Trace public void sendFriendNotifications( final FriendNotificationsDto dto, final CategoryName categoryName, diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java index 92f19f479..e48e977d5 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java @@ -10,6 +10,7 @@ import site.timecapsulearchive.notification.data.dto.GroupAcceptNotificationDto; import site.timecapsulearchive.notification.data.dto.GroupInviteNotificationDto; import site.timecapsulearchive.notification.entity.CategoryName; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; @@ -20,6 +21,7 @@ public class GroupFcmManagerImpl implements GroupFcmManager { private final S3PreSignedUrlManager s3PreSignedUrlManager; + @Trace public void sendGroupInviteNotifications( final GroupInviteNotificationDto dto, final CategoryName categoryName, @@ -44,6 +46,7 @@ public void sendGroupInviteNotifications( } } + @Trace public void sendGroupAcceptNotification( final GroupAcceptNotificationDto dto, final CategoryName categoryName, diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java index 5049da2dc..7e1b36907 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java @@ -7,6 +7,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.stereotype.Repository; +import site.timecapsulearchive.notification.global.aop.Trace; @Repository @RequiredArgsConstructor @@ -15,6 +16,7 @@ public class MemberRepository { private final JdbcTemplate jdbcTemplate; private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; + @Trace public String findFCMToken(Long memberId) { String sql = "SELECT m.fcm_token FROM member m WHERE m.member_id = ? and m.deleted_at is null"; @@ -25,6 +27,7 @@ public String findFCMToken(Long memberId) { ); } + @Trace public List findFCMTokens(List memberIds) { final String sql = "SELECT m.fcm_token FROM member m WHERE m.member_id IN (:memberIds) and m.deleted_at is null"; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java index 30556d072..3cb10a9b4 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Repository; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationStatus; +import site.timecapsulearchive.notification.global.aop.Trace; @Repository @RequiredArgsConstructor @@ -19,6 +20,7 @@ public class NotificationQueryRepositoryImpl implements NotificationQueryReposit private final JdbcTemplate jdbcTemplate; + @Trace public void bulkSave(List notifications) { jdbcTemplate.batchUpdate( """ diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java index f3b75431c..502f95900 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java @@ -9,6 +9,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.fcm.capsuleskin.CapsuleSkinFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; @@ -18,14 +19,13 @@ @RequiredArgsConstructor public class CapsuleSkinAlarmService implements CapsuleSkinAlarmListener { - private final CapsuleSkinFcmManager capsuleSkinFcmManager; - private final NotificationRepository notificationRepository; private final NotificationCategoryRepository notificationCategoryRepository; private final MemberRepository memberRepository; private final TransactionTemplate transactionTemplate; + @Trace public void sendCapsuleSkinAlarm(final CapsuleSkinNotificationSendDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override @@ -42,5 +42,4 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { final String fcmToken = memberRepository.findFCMToken(dto.memberId()); capsuleSkinFcmManager.sendCapsuleSkinNotification(dto, CategoryName.CAPSULE_SKIN, fcmToken); } - } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java index dba816810..a87f3e98a 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java @@ -11,6 +11,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.fcm.friend.FriendFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; @@ -26,7 +27,8 @@ public class FriendAlarmService implements FriendAlarmListener { private final MemberRepository memberRepository; private final TransactionTemplate transactionTemplate; - + @Trace + @Override public void sendFriendRequestNotification(final FriendNotificationDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override @@ -46,6 +48,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } } + @Trace + @Override public void sendFriendAcceptNotification(final FriendNotificationDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override @@ -65,7 +69,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } } - + @Trace + @Override public void sendFriendRequestNotifications(final FriendNotificationsDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java index ef0728e08..96adece03 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java @@ -11,6 +11,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; +import site.timecapsulearchive.notification.global.aop.Trace; import site.timecapsulearchive.notification.infra.fcm.group.GroupFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; @@ -26,7 +27,8 @@ public class GroupAlarmService implements GroupAlarmListener { private final MemberRepository memberRepository; private final TransactionTemplate transactionTemplate; - + @Trace + @Override public void sendGroupInviteNotification(final GroupInviteNotificationDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override @@ -44,6 +46,7 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } } + @Trace @Override public void sendGroupAcceptNotification(GroupAcceptNotificationDto dto) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { diff --git a/backend/notification/src/main/resources/logback-spring.xml b/backend/notification/src/main/resources/logback-spring.xml index 4b25a32da..372ba3c5a 100644 --- a/backend/notification/src/main/resources/logback-spring.xml +++ b/backend/notification/src/main/resources/logback-spring.xml @@ -2,7 +2,7 @@ - [%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n + [%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - [trace] %msg%n @@ -12,7 +12,7 @@ INFO - [%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n + [%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - [trace] %msg%n From d7bfbcf09d2dca75a4eef4af5fda3195e61c67f0 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Fri, 9 Aug 2024 19:09:00 +0900 Subject: [PATCH 03/14] =?UTF-8?q?fix=20:=20=EC=BA=A1=EC=8A=90=20=EC=8A=A4?= =?UTF-8?q?=ED=82=A8=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20fcm=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/capsuleskin/CapsuleSkinAlarmService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java index 502f95900..89dae3faf 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java @@ -40,6 +40,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { }); final String fcmToken = memberRepository.findFCMToken(dto.memberId()); - capsuleSkinFcmManager.sendCapsuleSkinNotification(dto, CategoryName.CAPSULE_SKIN, fcmToken); + if (fcmToken != null && fcmToken.isBlank()) { + capsuleSkinFcmManager.sendCapsuleSkinNotification(dto, CategoryName.CAPSULE_SKIN, + fcmToken); + } } } From 57a0b88fa2a2c44528b1d36dfdfa6dafa48beb31 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Fri, 9 Aug 2024 22:10:17 +0900 Subject: [PATCH 04/14] =?UTF-8?q?fix=20:=20=EC=95=8C=EB=A6=BC=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EC=8B=9C=20=EA=B2=80=EC=A6=9D=20=EC=A1=B0=EA=B1=B4?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/member/MemberRepository.java | 31 ++++++++++----- .../capsuleskin/CapsuleSkinAlarmService.java | 10 +++-- .../dto/MemberNotificationInfoDto.java | 8 ++++ .../service/friend/FriendAlarmService.java | 39 +++++++++++-------- .../service/group/GroupAlarmService.java | 31 ++++++++------- .../validator/NotificationSendValidator.java | 15 +++++++ 6 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/service/dto/MemberNotificationInfoDto.java create mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/service/validator/NotificationSendValidator.java diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java index 7e1b36907..c97ea21d2 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java @@ -2,41 +2,52 @@ import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.stereotype.Repository; import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; @Repository @RequiredArgsConstructor public class MemberRepository { - private final JdbcTemplate jdbcTemplate; private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; @Trace - public String findFCMToken(Long memberId) { - String sql = "SELECT m.fcm_token FROM member m WHERE m.member_id = ? and m.deleted_at is null"; + public MemberNotificationInfoDto findFCMToken(Long memberId) { + final String sql = """ + SELECT m.fcm_token, m.notification_enabled + FROM member m + WHERE m.member_id = :memberId and m.deleted_at is null + """; - return jdbcTemplate.queryForObject( + final SqlParameterSource parameters = new MapSqlParameterSource("memberId", memberId); + + return namedParameterJdbcTemplate.queryForObject( sql, - (rs, rowNum) -> rs.getString("fcm_token"), - memberId + parameters, + (rs, rowNum) -> new MemberNotificationInfoDto(rs.getString("fcm_token"), + rs.getBoolean("notification_enabled")) ); } @Trace - public List findFCMTokens(List memberIds) { - final String sql = "SELECT m.fcm_token FROM member m WHERE m.member_id IN (:memberIds) and m.deleted_at is null"; + public List findFCMTokens(List memberIds) { + final String sql = """ + SELECT m.fcm_token, m.notification_enabled + FROM member m + WHERE m.member_id IN (:memberIds) and m.deleted_at is null + """; final SqlParameterSource parameters = new MapSqlParameterSource("memberIds", memberIds); return namedParameterJdbcTemplate.query( sql, parameters, - (rs, rowNum) -> rs.getString("fcm_token") + (rs, rowNum) -> new MemberNotificationInfoDto(rs.getString("fcm_token"), + rs.getBoolean("notification_enabled")) ); } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java index 89dae3faf..a9baa3e44 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java @@ -14,12 +14,15 @@ import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; import site.timecapsulearchive.notification.repository.notification.NotificationRepository; +import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; +import site.timecapsulearchive.notification.service.validator.NotificationSendValidator; @Service @RequiredArgsConstructor public class CapsuleSkinAlarmService implements CapsuleSkinAlarmListener { private final CapsuleSkinFcmManager capsuleSkinFcmManager; + private final NotificationSendValidator notificationSendValidator; private final NotificationRepository notificationRepository; private final NotificationCategoryRepository notificationCategoryRepository; private final MemberRepository memberRepository; @@ -39,10 +42,11 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final String fcmToken = memberRepository.findFCMToken(dto.memberId()); - if (fcmToken != null && fcmToken.isBlank()) { + final MemberNotificationInfoDto notificationInfoDto = memberRepository.findFCMToken( + dto.memberId()); + if (notificationSendValidator.canSend(notificationInfoDto)) { capsuleSkinFcmManager.sendCapsuleSkinNotification(dto, CategoryName.CAPSULE_SKIN, - fcmToken); + notificationInfoDto.fcmToken()); } } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/dto/MemberNotificationInfoDto.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/dto/MemberNotificationInfoDto.java new file mode 100644 index 000000000..685a67a03 --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/dto/MemberNotificationInfoDto.java @@ -0,0 +1,8 @@ +package site.timecapsulearchive.notification.service.dto; + +public record MemberNotificationInfoDto( + String fcmToken, + Boolean notificationEnabled +) { + +} \ No newline at end of file diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java index a87f3e98a..150a50100 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java @@ -16,12 +16,15 @@ import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; import site.timecapsulearchive.notification.repository.notification.NotificationRepository; +import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; +import site.timecapsulearchive.notification.service.validator.NotificationSendValidator; @Service @RequiredArgsConstructor public class FriendAlarmService implements FriendAlarmListener { private final FriendFcmManager friendFcmManager; + private final NotificationSendValidator notificationSendValidator; private final NotificationRepository notificationRepository; private final NotificationCategoryRepository notificationCategoryRepository; private final MemberRepository memberRepository; @@ -42,9 +45,11 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final String fcmToken = memberRepository.findFCMToken(dto.targetId()); - if (fcmToken != null && !fcmToken.isBlank()) { - friendFcmManager.sendFriendNotification(dto, CategoryName.FRIEND_REQUEST, fcmToken); + final MemberNotificationInfoDto notificationInfoDto = memberRepository.findFCMToken( + dto.targetId()); + if (notificationSendValidator.canSend(notificationInfoDto)) { + friendFcmManager.sendFriendNotification(dto, CategoryName.FRIEND_REQUEST, + notificationInfoDto.fcmToken()); } } @@ -63,9 +68,11 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final String fcmToken = memberRepository.findFCMToken(dto.targetId()); - if (fcmToken != null && !fcmToken.isBlank()) { - friendFcmManager.sendFriendNotification(dto, CategoryName.FRIEND_ACCEPT, fcmToken); + final MemberNotificationInfoDto notificationInfoDto = memberRepository.findFCMToken( + dto.targetId()); + if (notificationSendValidator.canSend(notificationInfoDto)) { + friendFcmManager.sendFriendNotification(dto, CategoryName.FRIEND_ACCEPT, + notificationInfoDto.fcmToken()); } } @@ -83,16 +90,16 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final List fcmTokens = getTargetFcmTokens(dto.targetIds()); - if (fcmTokens != null && !fcmTokens.isEmpty()) { - friendFcmManager.sendFriendNotifications(dto, CategoryName.FRIEND_ACCEPT, fcmTokens); - } - } + final List notificationInfoDtos = memberRepository.findFCMTokens( + dto.targetIds()); + if (notificationInfoDtos != null && !notificationInfoDtos.isEmpty()) { + List filteredFcmTokens = notificationInfoDtos.stream() + .filter(notificationSendValidator::canSend) + .map(MemberNotificationInfoDto::fcmToken) + .toList(); - private List getTargetFcmTokens(List targetIds) { - return memberRepository.findFCMTokens(targetIds) - .stream() - .toList(); + friendFcmManager.sendFriendNotifications(dto, CategoryName.FRIEND_ACCEPT, + filteredFcmTokens); + } } - } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java index 96adece03..d9cd10800 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java @@ -16,12 +16,15 @@ import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; import site.timecapsulearchive.notification.repository.notification.NotificationRepository; +import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; +import site.timecapsulearchive.notification.service.validator.NotificationSendValidator; @Service @RequiredArgsConstructor public class GroupAlarmService implements GroupAlarmListener { private final GroupFcmManager groupFcmManager; + private final NotificationSendValidator notificationSendValidator; private final NotificationRepository notificationRepository; private final NotificationCategoryRepository notificationCategoryRepository; private final MemberRepository memberRepository; @@ -40,9 +43,16 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - List fcmTokens = getTargetFcmTokens(dto.targetIds()); - if (fcmTokens != null && !fcmTokens.isEmpty()) { - groupFcmManager.sendGroupInviteNotifications(dto, CategoryName.GROUP_INVITE, fcmTokens); + List notificationInfoDtos = memberRepository.findFCMTokens( + dto.targetIds()); + if (notificationInfoDtos != null && !notificationInfoDtos.isEmpty()) { + List filteredFcmTokens = notificationInfoDtos.stream() + .filter(notificationSendValidator::canSend) + .map(MemberNotificationInfoDto::fcmToken) + .toList(); + + groupFcmManager.sendGroupInviteNotifications(dto, CategoryName.GROUP_INVITE, + filteredFcmTokens); } } @@ -62,16 +72,11 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final String fcmToken = memberRepository.findFCMToken(dto.targetId()); - if (fcmToken != null && !fcmToken.isBlank()) { - groupFcmManager.sendGroupAcceptNotification(dto, CategoryName.FRIEND_ACCEPT, fcmToken); + final MemberNotificationInfoDto notificationInfoDto = memberRepository.findFCMToken( + dto.targetId()); + if (notificationSendValidator.canSend(notificationInfoDto)) { + groupFcmManager.sendGroupAcceptNotification(dto, CategoryName.FRIEND_ACCEPT, + notificationInfoDto.fcmToken()); } } - - private List getTargetFcmTokens(List targetIds) { - return memberRepository.findFCMTokens(targetIds) - .stream() - .toList(); - } - } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/validator/NotificationSendValidator.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/validator/NotificationSendValidator.java new file mode 100644 index 000000000..9741ff31e --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/validator/NotificationSendValidator.java @@ -0,0 +1,15 @@ +package site.timecapsulearchive.notification.service.validator; + +import org.springframework.stereotype.Component; +import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; + +@Component +public class NotificationSendValidator { + + public boolean canSend(MemberNotificationInfoDto memberNotificationInfoDto) { + return memberNotificationInfoDto != null + && memberNotificationInfoDto.notificationEnabled() + && memberNotificationInfoDto.fcmToken() != null + && !memberNotificationInfoDto.fcmToken().isBlank(); + } +} From 4aca4792f8eea098615f3db9cfb1567342571162 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 12:00:01 +0900 Subject: [PATCH 05/14] =?UTF-8?q?fix=20:=20=ED=81=90,=20=EC=9D=B5=EC=8A=A4?= =?UTF-8?q?=EC=B2=B4=EC=9D=B8=EC=A7=80=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/service/friend/FriendAlarmListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java index d50038282..e39fb442c 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java @@ -34,8 +34,8 @@ public interface FriendAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.friendRequests.queue", durable = "true"), - exchange = @Exchange(value = "notification.friendRequests.exchange"), + value = @Queue(value = "batch.notification.friendRequests.queue", durable = "true"), + exchange = @Exchange(value = "batch.notification.friendRequests.exchange"), key = "notification.friendRequests.queue" ), returnExceptions = "false", From 264392b1cafa13adcd551d6391eb3944bc7f3391 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 12:33:13 +0900 Subject: [PATCH 06/14] =?UTF-8?q?fix=20:=20rabbitmq=20=ED=81=90=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/RabbitmqComponentConstants.java | 8 ++++---- .../global/config/RabbitmqConfig.java | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java index 87f632b4f..27bc0fd49 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java @@ -14,10 +14,10 @@ public enum RabbitmqComponentConstants { "fail.notification.friendRequest.queue"), FRIEND_REQUEST_NOTIFICATION_EXCHANGE("notification.friendRequest.exchange", "fail.notification.friendRequest.exchange"), - FRIEND_REQUESTS_NOTIFICATION_QUEUE("notification.friendRequests.queue", - "fail.notification.friendRequests.queue"), - FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("notification.friendRequests.exchange", - "fail.notification.friendRequests.exchange"), + FRIEND_REQUESTS_NOTIFICATION_QUEUE("batch.notification.friendRequests.queue", + "fail.batch.notification.friendRequests.queue"), + FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("batch.notification.friendRequests.exchange", + "fail.batch.notification.friendRequests.exchange"), FRIEND_ACCEPT_NOTIFICATION_QUEUE("notification.friendAccept.queue", "fail.notification.friendAccept.queue"), FRIEND_ACCEPT_NOTIFICATION_EXCHANGE("notification.friendAccept.exchange", diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java index 41a5d2ca0..ba4e531ce 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java @@ -8,8 +8,8 @@ import org.springframework.amqp.core.DirectExchange; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.annotation.EnableRabbit; +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; -import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -123,16 +123,16 @@ public Binding friendAcceptBinding() { } @Bean - public RabbitTemplate rabbitTemplate() { - RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory()); - rabbitTemplate.setMessageConverter(jsonMessageConverter()); - - return rabbitTemplate; + public Jackson2JsonMessageConverter jsonMessageConverter() { + return new Jackson2JsonMessageConverter(); } @Bean - public Jackson2JsonMessageConverter jsonMessageConverter() { - return new Jackson2JsonMessageConverter(); + public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() { + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); + factory.setConnectionFactory(connectionFactory()); + factory.setMessageConverter(jsonMessageConverter()); + return factory; } @Bean From 01bb25341648de9b4648034a94c5e291d384c54f Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 13:27:38 +0900 Subject: [PATCH 07/14] =?UTF-8?q?fix=20:=20rabbitmq=20=EB=8D=B0=EB=93=9C?= =?UTF-8?q?=EB=A0=88=ED=84=B0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/RabbitmqComponentConstants.java | 13 ++-- .../global/config/RabbitmqConfig.java | 63 +++++++++++++---- .../config/RabbitmqFailComponentConfig.java | 67 ++++++++++++------- .../capsuleskin/CapsuleSkinAlarmListener.java | 7 +- .../service/friend/FriendAlarmListener.java | 21 ++++-- .../service/group/GroupAlarmListener.java | 13 +++- 6 files changed, 134 insertions(+), 50 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java index 27bc0fd49..f22d6fe14 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java @@ -6,24 +6,25 @@ @Getter public enum RabbitmqComponentConstants { - CAPSULE_SKIN_QUEUE("notification.createCapsuleSkin.queue", + CAPSULE_SKIN_NOTIFICATION_QUEUE("notification.createCapsuleSkin.queue", "fail.notification.createCapsuleSkin.queue"), - CAPSULE_SKIN_EXCHANGE("notification.createCapsuleSkin.exchange", + CAPSULE_SKIN_NOTIFICATION_EXCHANGE("notification.createCapsuleSkin.exchange", "fail.notification.createCapsuleSkin.exchange"), FRIEND_REQUEST_NOTIFICATION_QUEUE("notification.friendRequest.queue", "fail.notification.friendRequest.queue"), FRIEND_REQUEST_NOTIFICATION_EXCHANGE("notification.friendRequest.exchange", "fail.notification.friendRequest.exchange"), - FRIEND_REQUESTS_NOTIFICATION_QUEUE("batch.notification.friendRequests.queue", + BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE("batch.notification.friendRequests.queue", "fail.batch.notification.friendRequests.queue"), - FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("batch.notification.friendRequests.exchange", + BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("batch.notification.friendRequests.exchange", "fail.batch.notification.friendRequests.exchange"), FRIEND_ACCEPT_NOTIFICATION_QUEUE("notification.friendAccept.queue", "fail.notification.friendAccept.queue"), FRIEND_ACCEPT_NOTIFICATION_EXCHANGE("notification.friendAccept.exchange", "fail.notification.friendAccept.exchange"), - GROUP_INVITE_QUEUE("notification.groupInvite.queue", "fail.notification.groupInvite.queue"), - GROUP_INVITE_EXCHANGE("notification.groupInvite.exchange", + GROUP_INVITE_NOTIFICATION_QUEUE("notification.groupInvite.queue", + "fail.notification.groupInvite.queue"), + GROUP_INVITE_NOTIFICATION_EXCHANGE("notification.groupInvite.exchange", "fail.notification.groupInvite.exchange"), GROUP_ACCEPT_NOTIFICATION_QUEUE("notification.groupAccept.queue", "fail.notification.groupAccept.queue"), diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java index ba4e531ce..159945b20 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java @@ -7,6 +7,7 @@ import org.springframework.amqp.core.BindingBuilder; import org.springframework.amqp.core.DirectExchange; import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.QueueBuilder; import org.springframework.amqp.rabbit.annotation.EnableRabbit; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; @@ -24,13 +25,17 @@ public class RabbitmqConfig { @Bean public Queue capsuleSkinQueue() { - return new Queue(RabbitmqComponentConstants.CAPSULE_SKIN_QUEUE.getSuccessComponent(), true); + return QueueBuilder.durable( + RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); } @Bean public DirectExchange capsuleSkinExchange() { return new DirectExchange( - RabbitmqComponentConstants.CAPSULE_SKIN_EXCHANGE.getSuccessComponent()); + RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getSuccessComponent()); } @Bean @@ -43,13 +48,17 @@ public Binding capsuleSkinBinding() { @Bean public Queue groupInviteQueue() { - return new Queue(RabbitmqComponentConstants.GROUP_INVITE_QUEUE.getSuccessComponent(), true); + return QueueBuilder.durable( + RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); } @Bean public DirectExchange groupInviteExchange() { return new DirectExchange( - RabbitmqComponentConstants.GROUP_INVITE_EXCHANGE.getSuccessComponent()); + RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getSuccessComponent()); } @Bean @@ -62,8 +71,11 @@ public Binding groupInviteBinding() { @Bean public Queue groupAcceptQueue() { - return new Queue( - RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent(), true); + return QueueBuilder.durable( + RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); } @Bean @@ -82,9 +94,11 @@ public Binding groupAcceptBinding() { @Bean public Queue friendRequestQueue() { - return new Queue( - RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_QUEUE.getSuccessComponent(), - true); + return QueueBuilder.durable( + RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); } @Bean @@ -103,9 +117,11 @@ public Binding friendRequestBinding() { @Bean public Queue friendAcceptQueue() { - return new Queue( - RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent(), - true); + return QueueBuilder.durable( + RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); } @Bean @@ -122,6 +138,29 @@ public Binding friendAcceptBinding() { .withQueueName(); } + @Bean + public Queue batchFriendRequestsQueue() { + return QueueBuilder.durable( + RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE.getSuccessComponent()) + .withArgument("x-dead-letter-exchange", + RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getFailComponent()) + .build(); + } + + @Bean + public DirectExchange batchFriendRequestsExchange() { + return new DirectExchange( + RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getSuccessComponent()); + } + + @Bean + public Binding batchFriendRequestsBinding() { + return BindingBuilder + .bind(batchFriendRequestsQueue()) + .to(batchFriendRequestsExchange()) + .withQueueName(); + } + @Bean public Jackson2JsonMessageConverter jsonMessageConverter() { return new Jackson2JsonMessageConverter(); diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java index 22c70f011..02b0731a0 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java @@ -2,7 +2,7 @@ import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; -import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.FanoutExchange; import org.springframework.amqp.core.Queue; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,40 +12,40 @@ public class RabbitmqFailComponentConfig { @Bean public Queue capsuleSkinFailQueue() { - return new Queue(RabbitmqComponentConstants.CAPSULE_SKIN_QUEUE.getFailComponent(), true); + return new Queue( + RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_QUEUE.getFailComponent(), true); } @Bean - public DirectExchange capsuleSkinFailExchange() { - return new DirectExchange( - RabbitmqComponentConstants.CAPSULE_SKIN_EXCHANGE.getFailComponent()); + public FanoutExchange capsuleSkinFailExchange() { + return new FanoutExchange( + RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getFailComponent()); } @Bean public Binding capsuleSkinFailBinding() { return BindingBuilder .bind(capsuleSkinFailQueue()) - .to(capsuleSkinFailExchange()) - .withQueueName(); + .to(capsuleSkinFailExchange()); } @Bean public Queue groupInviteFailQueue() { - return new Queue(RabbitmqComponentConstants.GROUP_INVITE_QUEUE.getFailComponent(), true); + return new Queue( + RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_QUEUE.getFailComponent(), true); } @Bean - public DirectExchange groupInviteFailExchange() { - return new DirectExchange( - RabbitmqComponentConstants.GROUP_INVITE_EXCHANGE.getFailComponent()); + public FanoutExchange groupInviteFailExchange() { + return new FanoutExchange( + RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getFailComponent()); } @Bean public Binding groupInviteFailBinding() { return BindingBuilder .bind(groupInviteFailQueue()) - .to(groupInviteFailExchange()) - .withQueueName(); + .to(groupInviteFailExchange()); } @@ -56,8 +56,8 @@ public Queue groupAcceptFailQueue() { } @Bean - public DirectExchange groupAcceptFailExchange() { - return new DirectExchange( + public FanoutExchange groupAcceptFailExchange() { + return new FanoutExchange( RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent()); } @@ -65,8 +65,7 @@ public DirectExchange groupAcceptFailExchange() { public Binding groupAcceptFailBinding() { return BindingBuilder .bind(groupAcceptFailQueue()) - .to(groupAcceptFailExchange()) - .withQueueName(); + .to(groupAcceptFailExchange()); } @@ -78,8 +77,8 @@ public Queue friendRequestFailQueue() { } @Bean - public DirectExchange friendRequestFailExchange() { - return new DirectExchange( + public FanoutExchange friendRequestFailExchange() { + return new FanoutExchange( RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_EXCHANGE.getFailComponent()); } @@ -87,8 +86,7 @@ public DirectExchange friendRequestFailExchange() { public Binding friendRequestFailBinding() { return BindingBuilder .bind(friendRequestFailQueue()) - .to(friendRequestFailExchange()) - .withQueueName(); + .to(friendRequestFailExchange()); } @Bean @@ -99,8 +97,8 @@ public Queue friendAcceptFailQueue() { } @Bean - public DirectExchange friendAcceptFailExchange() { - return new DirectExchange( + public FanoutExchange friendAcceptFailExchange() { + return new FanoutExchange( RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent()); } @@ -108,7 +106,26 @@ public DirectExchange friendAcceptFailExchange() { public Binding friendAcceptFailBinding() { return BindingBuilder .bind(friendAcceptFailQueue()) - .to(friendAcceptFailExchange()) - .withQueueName(); + .to(friendAcceptFailExchange()); + } + + @Bean + public Queue batchFriendRequestsFailQueue() { + return new Queue( + RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE.getFailComponent(), + true); + } + + @Bean + public FanoutExchange batchFriendRequestsFailExchange() { + return new FanoutExchange( + RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getFailComponent()); + } + + @Bean + public Binding batchFriendRequestsFailBinding() { + return BindingBuilder + .bind(batchFriendRequestsFailQueue()) + .to(batchFriendRequestsFailExchange()); } } \ No newline at end of file diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java index 03f68f5ec..726da90ba 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java @@ -1,5 +1,6 @@ package site.timecapsulearchive.notification.service.capsuleskin; +import org.springframework.amqp.rabbit.annotation.Argument; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; @@ -10,7 +11,11 @@ public interface CapsuleSkinAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.createCapsuleSkin.queue", durable = "true"), + value = @Queue( + value = "notification.createCapsuleSkin.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.notification.createCapsuleSkin.exchange") + ), exchange = @Exchange(value = "notification.createCapsuleSkin.exchange"), key = "notification.createCapsuleSkin.queue" ), diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java index e39fb442c..1f6b5ef47 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java @@ -1,5 +1,6 @@ package site.timecapsulearchive.notification.service.friend; +import org.springframework.amqp.rabbit.annotation.Argument; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; @@ -11,7 +12,11 @@ public interface FriendAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.friendRequest.queue", durable = "true"), + value = @Queue( + value = "notification.friendRequest.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.notification.friendRequest.exchange") + ), exchange = @Exchange(value = "notification.friendRequest.exchange"), key = "notification.friendRequest.queue" ), @@ -22,7 +27,11 @@ public interface FriendAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.friendAccept.queue", durable = "true"), + value = @Queue( + value = "notification.friendAccept.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.notification.friendAccept.exchange") + ), exchange = @Exchange(value = "notification.friendAccept.exchange"), key = "notification.friendAccept.queue" ), @@ -34,9 +43,13 @@ public interface FriendAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "batch.notification.friendRequests.queue", durable = "true"), + value = @Queue( + value = "batch.notification.friendRequests.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.batch.notification.friendRequests.exchange") + ), exchange = @Exchange(value = "batch.notification.friendRequests.exchange"), - key = "notification.friendRequests.queue" + key = "batch.notification.friendRequests.queue" ), returnExceptions = "false", messageConverter = "jsonMessageConverter" diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java index 85296d065..9e0c6fc5e 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java @@ -1,5 +1,6 @@ package site.timecapsulearchive.notification.service.group; +import org.springframework.amqp.rabbit.annotation.Argument; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; @@ -11,7 +12,11 @@ public interface GroupAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.groupInvite.queue", durable = "true"), + value = @Queue( + value = "notification.groupInvite.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.notification.groupInvite.exchange") + ), exchange = @Exchange(value = "notification.groupInvite.exchange"), key = "notification.groupInvite.queue" ), @@ -23,7 +28,11 @@ public interface GroupAlarmListener { @RabbitListener( bindings = @QueueBinding( - value = @Queue(value = "notification.groupAccept.queue", durable = "true"), + value = @Queue( + value = "notification.groupAccept.queue", + durable = "true", + arguments = @Argument(name = "x-dead-letter-exchange", value = "fail.notification.groupAccept.exchange") + ), exchange = @Exchange(value = "notification.groupAccept.exchange"), key = "notification.groupAccept.queue" ), From 52e1c90b37b592ab45a62cf3291d8888f2546d17 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 16:32:54 +0900 Subject: [PATCH 08/14] =?UTF-8?q?fix=20:=20bulk=20send=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/friend/FriendAlarmService.java | 15 +++++++-------- .../service/group/GroupAlarmService.java | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java index 150a50100..370ffcee7 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java @@ -90,16 +90,15 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - final List notificationInfoDtos = memberRepository.findFCMTokens( - dto.targetIds()); - if (notificationInfoDtos != null && !notificationInfoDtos.isEmpty()) { - List filteredFcmTokens = notificationInfoDtos.stream() - .filter(notificationSendValidator::canSend) - .map(MemberNotificationInfoDto::fcmToken) - .toList(); + final List filteredFCMTokens = memberRepository.findFCMTokens(dto.targetIds()) + .stream() + .filter(notificationSendValidator::canSend) + .map(MemberNotificationInfoDto::fcmToken) + .toList(); + if (!filteredFCMTokens.isEmpty()) { friendFcmManager.sendFriendNotifications(dto, CategoryName.FRIEND_ACCEPT, - filteredFcmTokens); + filteredFCMTokens); } } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java index d9cd10800..746b31b2d 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java @@ -43,16 +43,16 @@ protected void doInTransactionWithoutResult(TransactionStatus status) { } }); - List notificationInfoDtos = memberRepository.findFCMTokens( - dto.targetIds()); - if (notificationInfoDtos != null && !notificationInfoDtos.isEmpty()) { - List filteredFcmTokens = notificationInfoDtos.stream() - .filter(notificationSendValidator::canSend) - .map(MemberNotificationInfoDto::fcmToken) - .toList(); + List filteredFCMTokens = memberRepository.findFCMTokens( + dto.targetIds()) + .stream() + .filter(notificationSendValidator::canSend) + .map(MemberNotificationInfoDto::fcmToken) + .toList(); + if (!filteredFCMTokens.isEmpty()) { groupFcmManager.sendGroupInviteNotifications(dto, CategoryName.GROUP_INVITE, - filteredFcmTokens); + filteredFCMTokens); } } From a946e992efde4208b162f59c75837e26c767aa80 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 16:44:15 +0900 Subject: [PATCH 09/14] =?UTF-8?q?fix=20:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => rabbitmq}/RabbitmqComponentConstants.java | 2 +- .../global/config/{ => rabbitmq}/RabbitmqConfig.java | 10 +++++++++- .../{ => rabbitmq}/RabbitmqFailComponentConfig.java | 2 +- .../config/{ => rabbitmq}/RabbitmqProperties.java | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/{ => rabbitmq}/RabbitmqComponentConstants.java (97%) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/{ => rabbitmq}/RabbitmqConfig.java (94%) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/{ => rabbitmq}/RabbitmqFailComponentConfig.java (98%) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/{ => rabbitmq}/RabbitmqProperties.java (88%) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java similarity index 97% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java index f22d6fe14..bf5c0d4d5 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqComponentConstants.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.config; +package site.timecapsulearchive.notification.global.config.rabbitmq; import java.util.Arrays; import lombok.Getter; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqConfig.java similarity index 94% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqConfig.java index 159945b20..36bace3b1 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqConfig.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqConfig.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.config; +package site.timecapsulearchive.notification.global.config.rabbitmq; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; @@ -11,6 +11,7 @@ import org.springframework.amqp.rabbit.annotation.EnableRabbit; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -194,4 +195,11 @@ public CachingConnectionFactory connectionFactory() { return connectionFactory; } + + @Bean + public RabbitTemplate rabbitTemplate() { + RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory()); + rabbitTemplate.setMessageConverter(jsonMessageConverter()); + return rabbitTemplate; + } } \ No newline at end of file diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqFailComponentConfig.java similarity index 98% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqFailComponentConfig.java index 02b0731a0..cf0b8dee2 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqFailComponentConfig.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqFailComponentConfig.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.config; +package site.timecapsulearchive.notification.global.config.rabbitmq; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqProperties.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqProperties.java similarity index 88% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqProperties.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqProperties.java index fc52d5282..d5040fe1a 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/RabbitmqProperties.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqProperties.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.config; +package site.timecapsulearchive.notification.global.config.rabbitmq; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; From f197c04022b5c05b31498e5c9c744f9b746600d6 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 16:44:55 +0900 Subject: [PATCH 10/14] =?UTF-8?q?feat=20:=20error=20handler=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/RabbitMQErrorHandler.java | 33 +++++++++++++++++++ .../capsuleskin/CapsuleSkinAlarmListener.java | 3 +- .../service/friend/FriendAlarmListener.java | 9 +++-- .../service/group/GroupAlarmListener.java | 6 ++-- 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java new file mode 100644 index 000000000..82437aa5d --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java @@ -0,0 +1,33 @@ +package site.timecapsulearchive.notification.global.error; + +import lombok.RequiredArgsConstructor; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler; +import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class RabbitMQErrorHandler implements RabbitListenerErrorHandler { + + private final RabbitTemplate rabbitTemplate; + + @Override + public Object handleError(Message amqpMessage, org.springframework.messaging.Message message, + ListenerExecutionFailedException exception) { + + MessageProperties properties = amqpMessage.getMessageProperties(); + + String routingKey = "fail." + properties.getReceivedRoutingKey(); + String exchange = "fail." + properties.getReceivedExchange(); + + properties.setHeader("x-exception-message", exception.getCause().getMessage()); + properties.setHeader("x-original-exchange", properties.getReceivedExchange()); + properties.setHeader("x-original-routing-key", properties.getReceivedRoutingKey()); + + rabbitTemplate.send(exchange, routingKey, amqpMessage); + return null; + } +} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java index 726da90ba..e63d192c8 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmListener.java @@ -20,7 +20,8 @@ public interface CapsuleSkinAlarmListener { key = "notification.createCapsuleSkin.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendCapsuleSkinAlarm(final CapsuleSkinNotificationSendDto dto); diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java index 1f6b5ef47..54bebf3b6 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmListener.java @@ -21,7 +21,8 @@ public interface FriendAlarmListener { key = "notification.friendRequest.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendFriendRequestNotification(final FriendNotificationDto dto); @@ -36,7 +37,8 @@ public interface FriendAlarmListener { key = "notification.friendAccept.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendFriendAcceptNotification(final FriendNotificationDto dto); @@ -52,7 +54,8 @@ public interface FriendAlarmListener { key = "batch.notification.friendRequests.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendFriendRequestNotifications(final FriendNotificationsDto dto); diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java index 9e0c6fc5e..d7ce77b42 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmListener.java @@ -21,7 +21,8 @@ public interface GroupAlarmListener { key = "notification.groupInvite.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendGroupInviteNotification(final GroupInviteNotificationDto dto); @@ -37,7 +38,8 @@ public interface GroupAlarmListener { key = "notification.groupAccept.queue" ), returnExceptions = "false", - messageConverter = "jsonMessageConverter" + messageConverter = "jsonMessageConverter", + errorHandler = "rabbitMQErrorHandler" ) void sendGroupAcceptNotification(final GroupAcceptNotificationDto dto); } From f38d8fbc7c776d16a5b75258f8fdbc5d5b48c8cb Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 16:54:54 +0900 Subject: [PATCH 11/14] =?UTF-8?q?fix=20:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/rabbitmq/RabbitmqComponentConstants.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java index bf5c0d4d5..e55e89c9d 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/config/rabbitmq/RabbitmqComponentConstants.java @@ -38,12 +38,4 @@ public enum RabbitmqComponentConstants { this.successComponent = successComponent; this.failComponent = failComponent; } - - public static String getFailComponent(String successComponent) { - return Arrays.stream(RabbitmqComponentConstants.values()) - .filter(constants -> constants.getSuccessComponent().equals(successComponent)) - .map(RabbitmqComponentConstants::getFailComponent) - .toList() - .get(0); - } } \ No newline at end of file From bebe4c97c712b16af4c6764063986e149e4d1eb7 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 17:19:39 +0900 Subject: [PATCH 12/14] =?UTF-8?q?feat=20:=20after=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/global/aop/LoggingComponent.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java index cab14c4e7..28a2ca669 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @@ -12,9 +13,14 @@ public class LoggingComponent { @Before("@annotation(site.timecapsulearchive.notification.global.aop.Trace)") - public void doTrace(JoinPoint joinPoint) { + public void doTraceBefore(JoinPoint joinPoint) { Object[] args = joinPoint.getArgs(); - log.info("{} args={}", joinPoint.getSignature(), args); + log.info("[before] {} args={}", joinPoint.getSignature(), args); + } + + @After("@annotation(site.timecapsulearchive.notification.global.aop.Trace)") + public void doTraceAfter(JoinPoint joinPoint) { + log.info("[after] {}", joinPoint.getSignature()); } } From 2a0b9dcd444d2c005293d3a2d204189ac5cd84f8 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sat, 10 Aug 2024 17:19:52 +0900 Subject: [PATCH 13/14] =?UTF-8?q?fix=20:=20=EC=97=90=EB=9F=AC=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/global/error/RabbitMQErrorHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java index 82437aa5d..b902789a7 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/error/RabbitMQErrorHandler.java @@ -1,6 +1,7 @@ package site.timecapsulearchive.notification.global.error; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -8,6 +9,7 @@ import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException; import org.springframework.stereotype.Component; +@Slf4j @Component @RequiredArgsConstructor public class RabbitMQErrorHandler implements RabbitListenerErrorHandler { @@ -17,6 +19,7 @@ public class RabbitMQErrorHandler implements RabbitListenerErrorHandler { @Override public Object handleError(Message amqpMessage, org.springframework.messaging.Message message, ListenerExecutionFailedException exception) { + log.error("message handle error", exception); MessageProperties properties = amqpMessage.getMessageProperties(); @@ -28,6 +31,7 @@ public Object handleError(Message amqpMessage, org.springframework.messaging.Mes properties.setHeader("x-original-routing-key", properties.getReceivedRoutingKey()); rabbitTemplate.send(exchange, routingKey, amqpMessage); + log.info("[{} to {}] {}", properties.getConsumerQueue(), exchange, amqpMessage); return null; } } From e2365d212d41608aa83c4aa97fcd7aef73215dbf Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 11 Aug 2024 20:09:09 +0900 Subject: [PATCH 14/14] =?UTF-8?q?fix=20:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/global/{aop => log}/LoggingComponent.java | 6 +++--- .../notification/global/{aop => log}/Trace.java | 2 +- .../infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java | 2 +- .../notification/infra/fcm/friend/FriendFcmManagerImpl.java | 2 +- .../notification/infra/fcm/group/GroupFcmManagerImpl.java | 2 +- .../notification/repository/member/MemberRepository.java | 2 +- .../notification/NotificationQueryRepositoryImpl.java | 2 +- .../service/capsuleskin/CapsuleSkinAlarmService.java | 2 +- .../notification/service/friend/FriendAlarmService.java | 2 +- .../notification/service/group/GroupAlarmService.java | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/{aop => log}/LoggingComponent.java (88%) rename backend/notification/src/main/java/site/timecapsulearchive/notification/global/{aop => log}/Trace.java (81%) diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/LoggingComponent.java similarity index 88% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/LoggingComponent.java index 28a2ca669..ff8fa1405 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/LoggingComponent.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/LoggingComponent.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.aop; +package site.timecapsulearchive.notification.global.log; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; @@ -12,14 +12,14 @@ @Component public class LoggingComponent { - @Before("@annotation(site.timecapsulearchive.notification.global.aop.Trace)") + @Before("@annotation(site.timecapsulearchive.notification.global.log.Trace)") public void doTraceBefore(JoinPoint joinPoint) { Object[] args = joinPoint.getArgs(); log.info("[before] {} args={}", joinPoint.getSignature(), args); } - @After("@annotation(site.timecapsulearchive.notification.global.aop.Trace)") + @After("@annotation(site.timecapsulearchive.notification.global.log.Trace)") public void doTraceAfter(JoinPoint joinPoint) { log.info("[after] {}", joinPoint.getSignature()); } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/Trace.java similarity index 81% rename from backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java rename to backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/Trace.java index fca893927..a519520a2 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/global/aop/Trace.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/global/log/Trace.java @@ -1,4 +1,4 @@ -package site.timecapsulearchive.notification.global.aop; +package site.timecapsulearchive.notification.global.log; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java index 95c91cc0e..5710d9756 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/capsuleskin/CapsuleSkinFcmManagerImpl.java @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; import site.timecapsulearchive.notification.data.dto.CapsuleSkinNotificationSendDto; import site.timecapsulearchive.notification.entity.CategoryName; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java index 9752f2602..cbcf512e1 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/friend/FriendFcmManagerImpl.java @@ -10,7 +10,7 @@ import site.timecapsulearchive.notification.data.dto.FriendNotificationDto; import site.timecapsulearchive.notification.data.dto.FriendNotificationsDto; import site.timecapsulearchive.notification.entity.CategoryName; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java index e48e977d5..015359ef5 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/group/GroupFcmManagerImpl.java @@ -10,7 +10,7 @@ import site.timecapsulearchive.notification.data.dto.GroupAcceptNotificationDto; import site.timecapsulearchive.notification.data.dto.GroupInviteNotificationDto; import site.timecapsulearchive.notification.entity.CategoryName; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.exception.MessageNotSendAbleException; import site.timecapsulearchive.notification.infra.fcm.FCMMessageData; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java index c97ea21d2..a634f6f61 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/member/MemberRepository.java @@ -6,7 +6,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.stereotype.Repository; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.service.dto.MemberNotificationInfoDto; @Repository diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java index 3cb10a9b4..9af18efec 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/repository/notification/NotificationQueryRepositoryImpl.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationStatus; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; @Repository @RequiredArgsConstructor diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java index a9baa3e44..ed80cedab 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/capsuleskin/CapsuleSkinAlarmService.java @@ -9,7 +9,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.fcm.capsuleskin.CapsuleSkinFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java index 370ffcee7..60f6fb357 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/friend/FriendAlarmService.java @@ -11,7 +11,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.fcm.friend.FriendFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java index 746b31b2d..f26e56fef 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/group/GroupAlarmService.java @@ -11,7 +11,7 @@ import site.timecapsulearchive.notification.entity.CategoryName; import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.entity.NotificationCategory; -import site.timecapsulearchive.notification.global.aop.Trace; +import site.timecapsulearchive.notification.global.log.Trace; import site.timecapsulearchive.notification.infra.fcm.group.GroupFcmManager; import site.timecapsulearchive.notification.repository.member.MemberRepository; import site.timecapsulearchive.notification.repository.notification.NotificationCategoryRepository;