第一种方法简单直观,但存在交易回滚的风险电子邮件已发送,从而使电子邮件无效。第二种方法更复杂,但它保证只有在用户创建实际成功时才发送电子邮件。第三种方法很简单,但是负责网络层的业务逻辑,它不应该需要知道。
没有一种更简单的方法,也许AOP驱动,这确保只有在用户创建事务实际成功时才会发送电子邮件?我认为第一种方法可能会失败是偏执的吗?
我们正在使用Java EE + Spring堆栈,并愿意集成其他API(AOP?Spring Integration? )实现这一点。
干杯!
解决方案我目前正在用来解决这个问题:
download.oracle/javaee/6/api/javax/transaction/Synchronization.html
Considering the common use case of a user creating a new account on a web application and the application sending a confirmation email to the user's address. From what I've seen, this is typically implemented in one of 3 ways:
The 1st approach is simple and straightforward, but there is a risk that the transaction is rolled back after the email was sent, thereby making the email invalid. The 2nd approach is more complicated, but it guarantees that the email is sent only if user creation has actually succeeded. The 3rd approach is simple but burdens the web layer with business logic that it shouldn't need to know.
Isn't there a simpler approach, maybe AOP-driven, that guarantees that the email will be sent only if the user creation transaction actually succeeded? Am I paranoid in thinking that the 1st approach could fail?
We're using a Java EE + Spring stack and are willing to integrate additional APIs (AOP? Spring Integration?) to achieve this.
Cheers!
解决方案Another option I am currently using to solve this problem:
download.oracle/javaee/6/api/javax/transaction/Synchronization.html
更多推荐
交易并发送电子邮件
发布评论