Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 비동기 처리용 Executor 분리, Firebase ThreadPool 커스텀, 알림 재전송 실패 로직 추가, 콜백 메소드를 활용한 Non-Blocking 처리 #501

Merged
merged 10 commits into from
May 27, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.official.pium.admin.service;

import com.official.pium.admin.mapper.AdminMapper;
import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.mapper.AdminMapper;
import com.official.pium.admin.service.dto.AdminLoginRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.official.pium.admin.service;

import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.domain.Registration;
import com.official.pium.admin.service.dto.RegistrationRequest;
import com.official.pium.admin.service.dto.RegistrationResponse;
import com.official.pium.admin.mapper.RegistrationMapper;
import com.official.pium.admin.repository.RegistrationRepository;
import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.service.dto.RegistrationRequest;
import com.official.pium.admin.service.dto.RegistrationResponse;
import com.official.pium.common.dto.DataResponse;
import com.official.pium.common.exception.AuthorizationException;
import com.official.pium.common.util.PhotoManager;
import com.official.pium.common.dto.DataResponse;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.official.pium.admin.service;

import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.petPlant.event.notification.NotificationEvent;
import com.official.pium.petPlant.repository.PetPlantRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -16,63 +19,49 @@ public class TestService {
private final PetPlantRepository petPlantRepository;
private final ApplicationEventPublisher publisher;

// public void sendWaterNotificationTest() {
// List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L);
// List<NotificationEvent> events = petPlants.stream()
// .map(plant -> NotificationEvent.builder()
// .title(plant.getNickname())
// .body("(테스트 중) 물을 줄 시간이에요!")
// .deviceToken(plant.getMember().getDeviceToken())
// .build()
// ).toList();
// log.info("동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
// publisher.publishEvent(NotificationEvents.from(events));
// log.info("동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
// }
Comment on lines -19 to -31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

주석은 테스트용으로 남겨둔건가요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니당

public void sendWaterNotificationAsyncRampTest() {
List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L);
List<NotificationEvent> events = petPlants.stream()
.map(plant -> NotificationEvent.builder()
.title(plant.getNickname())
.body("(테스트 중) 물을 줄 시간이에요!")
.deviceToken(plant.getMember().getDeviceToken())
.build()
).toList();

// public void sendWaterNotificationAsyncRampTest() {
// List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L);
// List<NotificationEvent> events = petPlants.stream()
// .map(plant -> NotificationEvent.builder()
// .title(plant.getNickname())
// .body("(테스트 중) 물을 줄 시간이에요!")
// .deviceToken(plant.getMember().getDeviceToken())
// .build()
// ).toList();
for (int i = 0; i < 100; i++) {
PetPlant petPlant = petPlants.get(i);
NotificationEvent event = NotificationEvent.builder()
.title(petPlant.getNickname())
.body("물줘")
.deviceToken(petPlant.getMember().getDeviceToken())
.build();
publisher.publishEvent(event);
}

// for (int i = 0; i < 100; i++) {
// PetPlant petPlant = petPlants.get(i);
// NotificationEvent event = NotificationEvent.builder()
// .title(petPlant.getNickname())
// .body("물줘")
// .deviceToken(petPlant.getMember().getDeviceToken())
// .build();
// publisher.publishEvent(event);
// }
log.info("비동기 테스트 램프업 시작");
for (int i = 0; i < 100; i++) {
NotificationEvent notificationEvent = events.get(i);
publisher.publishEvent(notificationEvent);
}
}

// log.info("비동기 테스트 램프업 시작");
// for (int i = 0; i < 100; i++) {
// NotificationEvent notificationEvent = events.get(i);
// publisher.publishEvent(notificationEvent);
// }
// }
public void sendWaterNotificationAsyncTest() {
List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L);
List<NotificationEvent> events = petPlants.stream()
.map(plant -> NotificationEvent.builder()
.title(plant.getNickname())
.body("(테스트 중) 물을 줄 시간이에요!")
.deviceToken(plant.getMember().getDeviceToken())
.build()
).toList();

// public void sendWaterNotificationAsyncTest() {
// List<PetPlant> petPlants = petPlantRepository.findAllByMemberId(7L);
// List<NotificationEvent> events = petPlants.stream()
// .map(plant -> NotificationEvent.builder()
// .title(plant.getNickname())
// .body("(테스트 중) 물을 줄 시간이에요!")
// .deviceToken(plant.getMember().getDeviceToken())
// .build()
// ).toList();
//
// int i = 1;
// log.info("비동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
// for (NotificationEvent event : events) {
// log.info(i++ + "번째 알림 이벤트");
// publisher.publishEvent(event);
// }
// log.info("비동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
// }
int i = 1;
log.info("비동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
for (NotificationEvent event : events) {
log.info(i++ + "번째 알림 이벤트");
publisher.publishEvent(event);
}
log.info("비동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.official.pium.admin.ui;

import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.service.RegistrationService;
import com.official.pium.admin.service.dto.RegistrationRequest;
import com.official.pium.admin.service.dto.RegistrationResponse;
import com.official.pium.admin.service.RegistrationService;
import com.official.pium.admin.domain.Admin;
import com.official.pium.member.ui.Auth;
import com.official.pium.common.dto.DataResponse;
import com.official.pium.member.ui.Auth;
import jakarta.validation.constraints.Positive;
import java.net.URI;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.official.pium.common.ui;

import com.official.pium.member.ui.Auth;
import com.official.pium.member.domain.Member;
import com.official.pium.common.exception.AuthenticationException;
import com.official.pium.member.domain.Member;
import com.official.pium.member.repository.MemberRepository;
import com.official.pium.member.ui.Auth;
import com.official.pium.sessionGroup.application.SessionGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.official.pium.common.util;

import java.io.File;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Component
public class PhotoLocalManager implements PhotoManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.official.pium.config;

import java.util.concurrent.Executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {
public class AsyncConfig {

@Override
public Executor getAsyncExecutor() {
@Bean("notificationAsyncExecutor")
public TaskExecutor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(40);
executor.setThreadNamePrefix("2024-Pium-Thread: ");
executor.initialize();
return executor;
}

@Bean("notificationCallBackExecutor")
public TaskExecutor getCallBackExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setThreadNamePrefix("2024-Pium-Call-Back-Thread: ");
executor.initialize();
return executor;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.official.pium.dictionaryPlant.application;

import com.official.pium.dictionaryPlant.domain.DictionaryPlant;
import com.official.pium.dictionaryPlant.repository.DictionaryPlantRepository;
import com.official.pium.petPlant.repository.PetPlantRepository;
import com.official.pium.common.dto.DataResponse;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantCreateRequest;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantResponse;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantSearchResponse;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantUpdateRequest;
import com.official.pium.dictionaryPlant.domain.DictionaryPlant;
import com.official.pium.dictionaryPlant.repository.DictionaryPlantRepository;
import com.official.pium.petPlant.repository.PetPlantRepository;
import java.util.List;
import java.util.NoSuchElementException;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.official.pium.dictionaryPlant.application.dto;

import com.official.pium.dictionaryPlant.domain.DictionaryPlant;
import com.official.pium.petPlant.domain.vo.WaterCycle;
import com.official.pium.dictionaryPlant.domain.vo.CareDetail;
import com.official.pium.dictionaryPlant.domain.vo.Classification;
import com.official.pium.dictionaryPlant.domain.vo.Property;
import com.official.pium.petPlant.domain.vo.Temperature;
import com.official.pium.petPlant.domain.vo.WaterCycle;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.official.pium.dictionaryPlant.application.dto;

import com.official.pium.petPlant.domain.vo.WaterCycle;
import com.official.pium.dictionaryPlant.domain.vo.CareDetail;
import com.official.pium.dictionaryPlant.domain.vo.Classification;
import com.official.pium.dictionaryPlant.domain.vo.Property;
import com.official.pium.petPlant.domain.vo.Temperature;
import com.official.pium.petPlant.domain.vo.WaterCycle;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import com.official.pium.admin.domain.Admin;
import com.official.pium.admin.ui.AdminAuth;
import com.official.pium.dictionaryPlant.application.DictionaryPlantService;
import com.official.pium.common.dto.DataResponse;
import com.official.pium.dictionaryPlant.application.DictionaryPlantService;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantCreateRequest;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantResponse;
import com.official.pium.dictionaryPlant.application.dto.DictionaryPlantSearchResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.official.pium.garden.application;

import com.official.pium.garden.application.dto.GardenCreateRequest;
import com.official.pium.garden.application.dto.GardenResponse;
import com.official.pium.garden.domain.Garden;
import com.official.pium.member.domain.Member;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.garden.domain.vo.GardenPlantState;
import com.official.pium.garden.repository.GardenRepository;
import com.official.pium.member.domain.Member;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.petPlant.repository.PetPlantRepository;
import com.official.pium.garden.application.dto.GardenCreateRequest;
import com.official.pium.garden.application.dto.GardenResponse;
import java.time.LocalDate;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.official.pium.garden.application.dto;

import com.official.pium.garden.domain.Garden;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.garden.domain.vo.GardenPlantState;
import com.official.pium.petPlant.domain.PetPlant;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.official.pium.common.domain.BaseEntity;
import com.official.pium.dictionaryPlant.domain.DictionaryPlant;
import com.official.pium.member.domain.Member;
import com.official.pium.garden.domain.vo.GardenPlantState;
import com.official.pium.member.domain.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.official.pium.garden.ui;

import com.official.pium.member.ui.Auth;
import com.official.pium.member.domain.Member;
import com.official.pium.garden.application.GardenService;
import com.official.pium.garden.application.dto.GardenCreateRequest;
import com.official.pium.garden.application.dto.GardenResponse;
import com.official.pium.member.domain.Member;
import com.official.pium.member.ui.Auth;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.official.pium.history.application;

import com.official.pium.petPlant.event.history.HistoryEvent;
import com.official.pium.petPlant.event.history.HistoryEvents;
import com.official.pium.petPlant.event.history.LastWaterDateEvent;
import com.official.pium.history.domain.History;
import com.official.pium.history.domain.HistoryCategory;
import com.official.pium.history.domain.vo.HistoryContent;
import com.official.pium.history.domain.HistoryType;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.history.domain.vo.HistoryContent;
import com.official.pium.history.repository.HistoryCategoryRepository;
import com.official.pium.history.repository.HistoryRepository;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.petPlant.event.history.HistoryEvent;
import com.official.pium.petPlant.event.history.HistoryEvents;
import com.official.pium.petPlant.event.history.LastWaterDateEvent;
import com.official.pium.petPlant.repository.PetPlantRepository;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.official.pium.history.application;

import com.official.pium.history.application.dto.HistoryResponse;
import com.official.pium.history.domain.History;
import com.official.pium.history.domain.HistoryType;
import com.official.pium.history.repository.HistoryRepository;
import com.official.pium.member.domain.Member;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.history.repository.HistoryRepository;
import com.official.pium.petPlant.repository.PetPlantRepository;
import com.official.pium.history.application.dto.HistoryResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.official.pium.history.domain;

import com.official.pium.common.domain.BaseEntity;
import com.official.pium.petPlant.domain.PetPlant;
import com.official.pium.history.domain.vo.HistoryContent;
import com.official.pium.petPlant.domain.PetPlant;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static org.springframework.data.domain.Sort.Direction.DESC;

import com.official.pium.member.ui.Auth;
import com.official.pium.member.domain.Member;
import com.official.pium.history.application.HistoryService;
import com.official.pium.history.application.dto.HistoryResponse;
import com.official.pium.member.domain.Member;
import com.official.pium.member.ui.Auth;
import jakarta.validation.constraints.Positive;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.official.pium.member.application;

import com.official.pium.member.domain.Member;
import com.official.pium.member.repository.MemberRepository;
import com.official.pium.member.application.dto.KaKaoAccessTokenResponse;
import com.official.pium.member.application.dto.KakaoMemberResponse;
import com.official.pium.member.application.dto.OAuthProvider;
import com.official.pium.member.domain.Member;
import com.official.pium.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Loading
Loading