java - Transaction and sending an email -


considering common use case of user creating new account on web application , application sending confirmation email user's address. i've seen, typically implemented in 1 of 3 ways:

  1. the web controller calls service method, creates user account , sends email, both within single transaction.
  2. the web controller calls service method (with tx propagation = never), invokes 1st method on create user account within transaction, , invokes 2nd method on send email.
  3. the web controller calls 1st service method, creates user account within transaction, 2nd service method sends email.

the 1st approach simple , straightforward, there risk transaction rolled after email sent, thereby making email invalid. 2nd approach more complicated, guarantees email sent if user creation has succeeded. 3rd approach simple burdens web layer business logic shouldn't need know.

isn't there simpler approach, maybe aop-driven, guarantees email sent if user creation transaction succeeded? paranoid in thinking 1st approach fail?

we're using java ee + spring stack , willing integrate additional apis (aop? spring integration?) achieve this.

cheers!

another option using solve problem:

http://download.oracle.com/javaee/6/api/javax/transaction/synchronization.html


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -