transactions / sending mails
Hi,
in one of my applications I want to rollback a transaction if sending a mail fails.
But I don't like the fact that the communication with the mail server happens during
the transaction as this operation could take some time, in which a database connection
is allocated (bound to the transaction). If the server gets busy or the mail server is
responding slowly, this could consume too many database connections.
One solution could be to establish a JMS queue
-> a JMS message is sent inside the transaction to indicate the need for a mail. If
the message is sent successfully, the application can be sure that the mail will be
sent and commit the transaction
-> the message consumer does the communication with the mail server
This would ensure that the mails are really sent but without synchronous behaviour
(and the problems related to this).
But this would require JTA transactions and also generally seems like a overkill of
the problem. Isn't there a simpler solution (without the need for JMS and JTA)?
Another way could be use JDBC instead of JMS and store the mail-data in a database
table. This table could be checked periodically for new entries. But this must be done
by a cluster-wide singleton component to prevent (theoretical) problems like duplicate
mails and therefore doesn't look like a good and easy solution.
Any comments or suggestions?
Actually this is not a problem specific to Spring, but nevertheless I hope that this
forum is the right place to discuss such issues.
Thanks
Christian