-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat(server): 메일전송을 비동기로 처리한다. #513
Changes from 5 commits
340184f
944973b
b82b9c3
1027b37
63f4e75
6710f76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.tyfserver.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurerSupport; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
@Configuration | ||
@EnableAsync | ||
public class AsyncConfig { | ||
|
||
@Bean(name = "mailExecutor") | ||
public ThreadPoolTaskExecutor mailExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setThreadNamePrefix("mail-executor"); | ||
return executor; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.MimeMessageHelper; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.context.Context; | ||
|
@@ -20,16 +21,15 @@ | |
import java.time.format.DateTimeFormatter; | ||
|
||
@Component | ||
@Async("mailExecutor") | ||
@RequiredArgsConstructor | ||
public class SmtpMailConnector { | ||
// todo 메일 전송 시간이 김. 비동기로 해볼까? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오... 언행일치 👍👍 멋진데? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 근데 주석 작성 조이 아님 ? ㅋㅋㅋ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아... 왜 수리가 적은줄 알았지...? 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅇㅇ나임ㅋㅋ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋㅋㅋㅋㅋㅋㅋ 조이임 |
||
|
||
private static final String PREFIX_SUBJECT = "[Thank You For]"; | ||
|
||
private final JavaMailSender javaMailSender; | ||
private final TemplateEngine templateEngine; | ||
|
||
|
||
public void sendVerificationCode(String mailAddress, String verificationCode) { | ||
Context context = new Context(); | ||
context.setVariable("code", verificationCode); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.example.tyfserver.payment.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@NoArgsConstructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 없어도 되지 않아? 왜 붙였어? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아고 저건 못봤넹 |
||
@Getter | ||
public class PaymentInfo { | ||
private UUID merchantUid; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,19 @@ | |
|
||
<script> | ||
async function cancelPay() { | ||
await jQuery.ajax({ | ||
url: "http://localhost:8080/payments/cancel", | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
data: JSON.stringify({ | ||
merchantUid: "935cfb0e-86e5-4458-8994-993cd7dc4e19" | ||
}) | ||
}).done(await function (data) { | ||
console.log("환불 성공"); | ||
console.log(data); | ||
}).fail(function (e) { | ||
alert("실패!") | ||
}); | ||
await jQuery.ajax({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. index.html 삭제할까 생각중인데 혹시 고친 이유가 있어? 이거 쓰나? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 응..비동기테스트는 직접 밖에 아직 방법을 못찾아서 삭제하기 전에 파노, 인치에게 프론트 개발 서버 또한 배포를 하면 어떨지에 대해서 말해볼까? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그건 따로 말하고 이건 그냥 삭제해도 될거같은데? 어차피 이거 쓰느 사람없고, 지금 api 서버에도 배포되어 있어서 아주 불편해 |
||
url: "http://localhost:8080/payments/cancel", | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
data: JSON.stringify({ | ||
merchantUid: "935cfb0e-86e5-4458-8994-993cd7dc4e19" | ||
}) | ||
}).done(await function (data) { | ||
console.log("환불 성공"); | ||
console.log(data); | ||
}).fail(function (e) { | ||
alert("실패!") | ||
}); | ||
} | ||
</script> | ||
|
||
|
@@ -39,26 +39,27 @@ | |
|
||
async function requestPay() { | ||
// 가맹점 서버에 Payment 생성 요청 | ||
const amount = 1000; | ||
const amount = 1100; | ||
const email = "ssop6403@gmail.com"; | ||
const pageName = "hwanorama"; | ||
const merchantUid = await createMerchantUid(amount, email, pageName); | ||
const itemId = "ITEM_1"; | ||
const merchantUid = await createMerchantUid(amount,itemId); | ||
// IMP.request_pay(param, callback) 호출 | ||
let result; | ||
await IMP.request_pay({ // param | ||
pay_method: "card", | ||
merchant_uid: merchantUid, | ||
name: pageName, | ||
name: itemId, | ||
amount: amount, | ||
buyer_email: email | ||
}, async function (rsp) { // callback | ||
if (rsp.success) { // 결제 성공 시: 결제 승인 또는 가상계좌 발급에 성공한 경우 | ||
console.log("아임포트 요청 성공"); | ||
console.log(rsp); | ||
await jQuery.ajax({ | ||
url: "http://localhost:8080/donations", // 가맹점 서버 | ||
url: "http://localhost:8080/payments/charge", // 가맹점 서버 | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
headers: {"Content-Type": "application/json", | ||
"Authorization" : ""}, | ||
data: JSON.stringify({ | ||
impUid: rsp.imp_uid, | ||
merchantUid: rsp.merchant_uid | ||
|
@@ -68,7 +69,7 @@ | |
console.log("결제 끝!"); | ||
console.log(data); | ||
result = { | ||
"impUid": data.impUid, | ||
"itemId": data.impUid, | ||
"merchantUid": data.merchantUid | ||
}; | ||
if(data.status === "success") { | ||
|
@@ -85,16 +86,15 @@ | |
}); | ||
} | ||
|
||
async function createMerchantUid(amount, email, pageName) { | ||
async function createMerchantUid(amount, itemId) { | ||
let merchantUid; | ||
await jQuery.ajax({ | ||
url: "http://localhost:8080/payments", // 가맹점 서버 | ||
url: "http://localhost:8080/payments/charge/ready", // 가맹점 서버 | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
headers: {"Content-Type": "application/json", | ||
"Authorization" : ""}, | ||
data: JSON.stringify({ | ||
amount: amount, | ||
email: email, | ||
pageName: pageName, | ||
itemId: itemId | ||
}), | ||
contentType: "application/json", | ||
dataType: "json" | ||
|
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.
우리가 지난번에 했던 http 미션에서
ExecutorService
가 있고 그것을 통해서 스레드 관리를 해줄 수가 있었는데링크,이것과 무슨 차이가 있는지 좀 찾아봤더니
출처 http://wonwoo.ml/index.php/post/2254
spring에서 조금 더 편하게 만든 스레드 관리 클래스였어!
내부적으로는
ThreadPoolExecutor
를 사용하고 있었고,workingQueue의 size도
new LinkedBlockingQueue<>(queueCapacity);
를 이용하고 있는 것을 볼 수가 있는데, 저 큐는ThreadPoolExecutor
에서도 사용하는 큐야! 스프링 별거를 다 도와주네 허허