-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Refactor] #267 - 유저 회원가입 이벤트 발행 비동기 처리
- Loading branch information
Showing
5 changed files
with
64 additions
and
41 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
moonshot-api/src/main/java/org/moonshot/config/AsyncConfig.java
This file contains 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,27 @@ | ||
package org.moonshot.config; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig implements AsyncConfigurer { | ||
|
||
@Override | ||
public Executor getAsyncExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(4); | ||
executor.setMaxPoolSize(4); | ||
executor.setQueueCapacity(4); | ||
executor.setKeepAliveSeconds(60); | ||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); | ||
executor.setThreadNamePrefix("async-executor-"); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
moonshot-api/src/main/java/org/moonshot/user/service/UserSignUpService.java
This file contains 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,31 @@ | ||
package org.moonshot.user.service; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.moonshot.discord.SignUpEvent; | ||
import org.moonshot.user.model.User; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserSignUpService { | ||
|
||
private final ApplicationEventPublisher eventPublisher; | ||
|
||
@Async | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public void publishSignUpEvent(User user) { | ||
eventPublisher.publishEvent(SignUpEvent.of( | ||
user.getName(), | ||
user.getEmail() == null ? "" : user.getEmail(), | ||
user.getSocialPlatform().toString(), | ||
LocalDateTime.now(), | ||
user.getImageUrl() | ||
)); | ||
} | ||
|
||
} |
This file contains 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 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 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