Skip to content

kit-cmd/NotificationServer

Repository files navigation

알림 서버

역할

서비스 역할
알림 서버 웹푸시 알림을 보냄

image

기술스택

  • Java 11
  • Spring Boot
  • Spring MVC
  • Redis
  • firebase FCM

아키텍처

아키텍처

제공 기능

기능 설명
알림 기능 - firebase의 FCM을 이용하여 알림 전송

프로젝트 진행 중 이슈

알림 전송

private void sendNotification(String data) {
        JSONObject jsonDataObject = new JSONObject(data);
        JSONArray disasterMsgArray = jsonDataObject.getJSONArray("DisasterMsg");
        JSONArray rowArray = disasterMsgArray.getJSONObject(1).getJSONArray("row"); // 변경된 부분
        JSONObject rowObject = rowArray.getJSONObject(0);
        String msg = rowObject.getString("msg");
        log.info("msg: {}", msg);

        try {
            Notification notification = Notification.builder()
                    .setTitle("실시간 재난 알림")
                    .setBody(msg) // Use the "msg" as the notification body
                    .build();

            List<String> tokens = notificationService.getToken();
            for (String token : tokens) {
                Message notificationMessage = Message.builder()
                        .setNotification(notification)
                        .setToken(token)
                        .build();

                try {
                    String response = FirebaseMessaging.getInstance().send(notificationMessage);
                    log.info("알림을 정상적으로 전송했습니다.: {}", response);
                } catch (FirebaseMessagingException e) {
                    log.error("알림 전송 실패: {}", e.getMessage());
                }
            }
        } catch (JSONException e) {
            log.error("Error parsing JSON data: {}", e.getMessage());
        }
    }

관련 자료

About

알림 서버 배포용

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published