Spring Transaction Synchronization of JDBC and JMS

后端 未结 3 1535
孤城傲影
孤城傲影 2021-02-01 19:40

I have a spring web app running on jboss that is currently configured to use the HibernateTransactionManager for db transactions and the JmsTransactionManager for jms. For jms w

3条回答
  •  孤城傲影
    2021-02-01 20:38

    If you are using Local transactions And the usecase is save to database and then send to jms

    Then there could be three cases :

    1. Exception just after receiving(before DB and JMS)

    No problem everything will be rolledback

    1. After saving to DB , we have exception

    If there is an insert operation,there will be mutiple rows in DB due to retries.With each retry , an insert will be done.And for JMS , message will go to DeadLetterQueue

    1. After saving to DB and sending to JMS , we have an exception

      If there is an insert operation,there will be mutiple rows in DB due to retries.With each retry , an insert will be done.And for JMS , message will go to DeadLetterQueue

    Now you dont want to use XA, so the solutions could be

    1)Check If(message.getJmsRedelivered() {…}

    If not , process it

    If its redelivered , check if you processed it already

    Check if the data is in database based on details in message

    Note that re-deliveries are rare so , this check is also rare and there is no overhead

    2)If your method is idempotent , then you dont need this check

    And regarding XA , XA guarantees that message is delivered only once And synchronize the transaction across multiple resources

    But with XA , you have overhead

    So if you can manage without XA , it is preferable

提交回复
热议问题