i designing jms application receives message queue , updates column in database. using tomcat , message listener listening of messages (no mdb , no spring mdp's). wanted best possible, robust design in case exception handling , transaction messages not lost.
should use jms session transaction mode , jdbc transaction. or jdbc transaction sufficient (without jms session commit or rollback) database table update.
thanks
a jdbc transaction not enough: if have read message, , database operation fails, , tomcat
shutdown, message lost.
if each message triggers insert/update in database, use client_acknowledge
mode:
final boolean transacted = false; final int ackmode = session.client_acknowledge; final queuesession queuesession = queueconnection.createqueuesession( transacted, ackmode);
so can read message, , update database. if database update successful, can acknowledge message using
message.acknowledge();
without acknowledge
, message redelivered: after restarting tomcat
, message listener should see message again. can use queuesession.recover()
restart delivery programatically.
since possible tomcat
shutdown right between successful db update , acknowledge, should make sure handle duplicate messages correctly.
a variation use transacted session:
final boolean transacted = true; // 2nd parameter ignored if session transacted final queuesession queuesession = queueconnection.createqueuesession( transacted, -1);
in mode can acknowledge multiple messages using single commit:
queuesession.commit();
you need mode, if multiple messages result in single database operation (you have collect messages, before can update database).
Comments
Post a Comment