Spring Transaction Synchronization of JDBC and JMS

后端 未结 3 1534
孤城傲影
孤城傲影 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:19

    This article might be of help Distributed transactions in Spring, with and without XA. I don't think it covers your case specifically - sending message + updating database.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-01 20:40

    Official Spring Boot repository contain JTA examples that combine JMS with JDBC based on Atomikos, Bitronix or Java EE server JBoss WildFly.

    Additionally I also created few examples that are located in my Github repository. This contains also non-Spring Boot (pure Spring) example.

    0 讨论(0)
提交回复
热议问题