spring - 通过发送电子邮件返回响应(http 状态)需要很长时间
问题描述
我有 REST 控制器,我在其中更新数据库,然后向用户发送电子邮件。在前端,接收响应状态的时间太长。如何解决?我可以在发送电子邮件之前以某种方式发送响应状态吗?
@PutMapping(value = "")
@Secured({("ROLE_USER"),("ROLE_SUPERIOR"), ("ROLE_ADMIN")})
public ResponseEntity updateApprovals(OAuth2Authentication auth, @RequestBody Approval approvals){
String email = auth.getName();
long userId = userService.getUserByEmail(email).get().getId();
int approval = Integer.parseInt(approvals.getApproval());
long doc_id = approvals.getDoc_id();
documentService.updateSharing(userId, doc_id, approval); // DB inserting and sending emails
return new ResponseEntity(HttpStatus.OK);
}
@Override
public void sendSimpleMessage(String to, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
emailSender.send(message);
}
解决方案
我认为像发送电子邮件这样的功能最好在单独的线程中工作。例如)thread pool
,,message queue
...
推荐阅读
- reactjs - 更新上下文而不替换现有值 (React)
- python - Tensorflow metal 插件已经注册错误
- python - 根据各种条件提取数据
- google-bigquery - 为什么我的谷歌云功能需要超过 9 分钟才能执行,而我本地机器上的相同功能需要 < 2 分钟
- amazon-web-services - 来自未加密 SNS 主题的消息未到达加密 SQS 队列
- git - 本地 .git 文件夹的大小 VS 克隆后
- python - 我正在尝试根据 Python 中每个列表的权重对一些列表进行批处理
- python - “ModuleNotFoundError:没有名为‘igdb.wrapper’的模块;‘igdb’不是包”igdb-api-v4
- javascript - 无法使用 js 隐藏 div,但我可以使用 js 显示 div。似乎“否则,如果”不起作用。有人可以看看这个吗?
- python - 在 Python 中使用递归时的 WHILE 与 IF