-
Notifications
You must be signed in to change notification settings - Fork 0
[UPLUS-29] api-message 초기 구현 #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
66be617
UPLUS-29 feat: Kafka 의존성 및 설정 추가
swthewhite 1d6c8af
UPLUS-29 feat: 알림 도메인 Enum 클래스 추가
swthewhite b98132e
UPLUS-29 feat: 알림 도메인 JPA Entity 추가
swthewhite 1aa4538
UPLUS-29 feat: 알림 도메인 Repository 추가
swthewhite 61a8f7e
UPLUS-29 feat: 알림 이벤트 DTO 추가
swthewhite e274d66
UPLUS-29 feat: Kafka 및 메트릭 설정 추가
swthewhite 0258ba6
UPLUS-29 feat: AES 암호화 유틸리티 및 보안 에러코드 추가
swthewhite 6be2706
UPLUS-29 feat: 알림 도메인 에러코드 추가
swthewhite f21ac9a
UPLUS-29 feat: 알림 서비스 레이어 추가
swthewhite cfd0822
UPLUS-29 feat: Mock 이메일/SMS 발송기 추가
swthewhite 959d6be
UPLUS-29 feat: Kafka 알림 컨슈머 추가
swthewhite 6798c92
UPLUS-29 feat: 테스트 데이터 SQL 스크립트 추가
swthewhite 6ccae8a
UPLUS-29 style: spotless 적용 (스페이스 4칸)
swthewhite 526f4a1
UPLUS-29 fix: 필드 매칭 오류 개선
swthewhite 3a614f8
UPLUS-29 style: checkstyle 개선
swthewhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/com/project/example/infra/repository/ExampleJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package com.project.example.infra.repository; | ||
|
|
||
| import com.project.example.infra.entity.ExampleEntity; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import com.project.example.infra.entity.ExampleEntity; | ||
|
|
||
| public interface ExampleJpaRepository extends JpaRepository<ExampleEntity, Long> {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 12 additions & 10 deletions
22
src/main/java/com/project/example/infra/repository/ExampleRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,26 @@ | ||
| package com.project.example.infra.repository; | ||
|
|
||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.project.example.infra.entity.ExampleEntity; | ||
| import com.project.global.exception.ApplicationException; | ||
| import com.project.global.exception.code.domain.ExampleErrorCode; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class ExampleRepositoryImpl implements ExampleRepository { | ||
|
|
||
| private final ExampleJpaRepository exampleJpaRepository; | ||
| private final ExampleJpaRepository exampleJpaRepository; | ||
|
|
||
| public ExampleEntity find(Long exampleId) { | ||
| return exampleJpaRepository | ||
| .findById(exampleId) | ||
| .orElseThrow(() -> new ApplicationException(ExampleErrorCode.EXAMPLE_NOT_FOUND)); | ||
| } | ||
| public ExampleEntity find(Long exampleId) { | ||
| return exampleJpaRepository | ||
| .findById(exampleId) | ||
| .orElseThrow(() -> new ApplicationException(ExampleErrorCode.EXAMPLE_NOT_FOUND)); | ||
| } | ||
|
|
||
| public void save(ExampleEntity example) { | ||
| exampleJpaRepository.save(example); | ||
| } | ||
| public void save(ExampleEntity example) { | ||
| exampleJpaRepository.save(example); | ||
| } | ||
| } |
26 changes: 14 additions & 12 deletions
26
src/main/java/com/project/example/service/ExampleService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,28 @@ | ||
| package com.project.example.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.project.example.controller.dto.SaveExampleRequest; | ||
| import com.project.example.infra.entity.ExampleEntity; | ||
| import com.project.example.infra.repository.ExampleRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ExampleService { | ||
|
|
||
| private final ExampleRepository exampleRepository; | ||
| private final ExampleRepository exampleRepository; | ||
|
|
||
| @Transactional | ||
| public ExampleEntity find(Long exampleId) { | ||
| return exampleRepository.find(exampleId); | ||
| } | ||
| @Transactional | ||
| public ExampleEntity find(Long exampleId) { | ||
| return exampleRepository.find(exampleId); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void save(SaveExampleRequest request) { | ||
| ExampleEntity exampleEntity = ExampleEntity.create(request); | ||
| exampleRepository.save(exampleEntity); | ||
| } | ||
| @Transactional | ||
| public void save(SaveExampleRequest request) { | ||
| ExampleEntity exampleEntity = ExampleEntity.create(request); | ||
| exampleRepository.save(exampleEntity); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.project.global.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.kafka.annotation.EnableKafka; | ||
| import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; | ||
| import org.springframework.kafka.core.ConsumerFactory; | ||
| import org.springframework.kafka.listener.ContainerProperties; | ||
|
|
||
| @Configuration | ||
| @EnableKafka | ||
| public class KafkaConfig { | ||
|
|
||
| @Bean | ||
| public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory( | ||
| ConsumerFactory<String, String> consumerFactory) { | ||
| ConcurrentKafkaListenerContainerFactory<String, String> factory = | ||
| new ConcurrentKafkaListenerContainerFactory<>(); | ||
|
|
||
| factory.setConsumerFactory(consumerFactory); | ||
| factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL); | ||
|
|
||
| return factory; | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/project/global/config/MetricsConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.project.global.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.Timer; | ||
|
|
||
| @Configuration | ||
| public class MetricsConfig { | ||
|
|
||
| @Bean | ||
| public Counter emailSuccessCounter(MeterRegistry registry) { | ||
| return Counter.builder("notification.sent.total") | ||
| .tag("channel", "EMAIL") | ||
| .tag("status", "SUCCESS") | ||
| .description("Total successful email notifications") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Counter emailFailCounter(MeterRegistry registry) { | ||
| return Counter.builder("notification.sent.total") | ||
| .tag("channel", "EMAIL") | ||
| .tag("status", "FAIL") | ||
| .description("Total failed email notifications") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Counter smsSuccessCounter(MeterRegistry registry) { | ||
| return Counter.builder("notification.sent.total") | ||
| .tag("channel", "SMS") | ||
| .tag("status", "SUCCESS") | ||
| .description("Total successful SMS notifications") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Counter smsFailCounter(MeterRegistry registry) { | ||
| return Counter.builder("notification.sent.total") | ||
| .tag("channel", "SMS") | ||
| .tag("status", "FAIL") | ||
| .description("Total failed SMS notifications") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Counter smsFallbackCounter(MeterRegistry registry) { | ||
| return Counter.builder("notification.sent.total") | ||
| .tag("channel", "SMS") | ||
| .tag("status", "FALLBACK") | ||
| .description("Total SMS fallback notifications") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Timer emailProcessingTimer(MeterRegistry registry) { | ||
| return Timer.builder("notification.processing.time") | ||
| .tag("channel", "EMAIL") | ||
| .description("Email notification processing time") | ||
| .register(registry); | ||
| } | ||
|
|
||
| @Bean | ||
| public Timer smsProcessingTimer(MeterRegistry registry) { | ||
| return Timer.builder("notification.processing.time") | ||
| .tag("channel", "SMS") | ||
| .description("SMS notification processing time") | ||
| .register(registry); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counter와Timer빈을 생성하는 데 상당한 양의 보일러플레이트 코드가 있습니다. 이 코드는 중복을 줄이고 유지보수성을 향상시키기 위해 리팩토링할 수 있습니다.메트릭 생성 및 등록 로직을 중앙에서 관리하는 팩토리 빈이나 헬퍼 클래스를 만드는 것을 고려해 보세요. 예를 들어,
getSuccessCounter(Channel channel)및getProcessingTimer(Channel channel)와 같은 메서드를 노출하는 단일NotificationMetrics빈을 가질 수 있으며, 존재하지 않을 경우 동적으로 생성할 수 있습니다. 이는NotificationService에서의 의존성 주입도 단순화할 것입니다.