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

Fix/#194 FcmSender에 비동기 기능 추가 #195

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/main/java/com/aliens/backend/global/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.aliens.backend.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Profile({"dev", "prod"})
@EnableAsync
@Configuration
public class AsyncConfig implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
int processors = Runtime.getRuntime().availableProcessors();
executor.setCorePoolSize(processors);
executor.setMaxPoolSize(processors * 2);
executor.setQueueCapacity(50);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("AsyncExecutor-");
executor.initialize();
return executor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.firebase.messaging.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -39,6 +40,7 @@ public FcmSender(MemberRepository memberRepository,
this.objectMapper = objectMapper;
}

@Async
public void sendBoardNotification(Comment comment, Member writer) {
Notification notification = Notification.builder()
.setTitle(FRIENDSHIP_TITLE)
Expand All @@ -53,6 +55,7 @@ public void sendBoardNotification(Comment comment, Member writer) {
// sendSingleFcm(message);
}

@Async
public void sendBoardNotification(Comment comment, List<Member> writers) {
Notification notification = Notification.builder()
.setTitle(FRIENDSHIP_TITLE)
Expand All @@ -69,6 +72,7 @@ public void sendBoardNotification(Comment comment, List<Member> writers) {
}
}

@Async
public void sendChatMessage(com.aliens.backend.chat.domain.Message message) {
var fcmMessage = createFcmMessage(message);
// sendSingleFcm(fcmMessage);
Expand Down Expand Up @@ -105,6 +109,7 @@ private void sendSingleFcm(Message message) {
}
}

@Async
public void sendMatchedNotification(Set<Member> members) {
List<String> tokens = members.stream().map(this::findFcmTokenByMember).toList();
Notification notification = Notification.builder()
Expand Down
Loading