Distributed messaging and database transaction sharing mode

Source: Internet
Author: User
Tags message queue

Transaction manager Org.springframework.jdbc.datasource.DataSourceTransactionManager (Abstractplatformtransactionmanager). Gettransaction creates connectionholder and saves it in transactionsynchronizationmanager.resources with Drivermanagerdatasource objects as key values. Make transactionsynchronizationmanager.issynchronizationactive= True indicates that transactionsynchronizationmanager.registersynchronization can be executed to save the corresponding Synchronizer to synchronizations such as Jmsresourcesynchronization 。 Using the Jmstemplate method in a transaction first creates a Jmsresourceholder and stores the Activemqconnectionfactor object as a key value in Transactionsynchronizationmanager.resources, the same The session and connection are shared within the transaction. The Activemqsession.createconsumer () method creates a consumer object that connects to the MQ server, the MQ server locks the message queue that the consumer wants to manipulate, other consumer objects cannot manipulate the message queue, and other producer objects can write, Execute Messageconsumer.close () to release the lock. The Jmstemplate.doreceive () method then reads the message from the MQ server, and the read message is only isolated by the MQ server, and the MQ server does not eventually delete the read message after executing session.commit (). The Session.commit () message can be rolled back without execution. Code snippet that indicates that if the session is managed by Datasourcetransactionmanager, execution Session.commit () can be ignored, Wait until the execution transaction method Datasourcetransactionmanager.commit () is executed again. Synchronizer Jmsresourcesynchronization registered to Transactionsynchronizationmanager,datasourcetransactionmanagEr.commit () will trigger the Aftercommit () method of all synchronizers in the transactionsynchronizationmanager.synchronizations, such as Jmsresourcesynchronization.aftercommit (), the final execution of Session.commit ().
            if (session.gettransacted ()) {                //commit necessary-but Avoid commit call within a JTA transaction.                if (issessionlocallytransacted (session)) {                    //transacted session created by the This template--commit.                    Jmsutils.commitifnecessary (session);                }            }

Distributed messaging and database transaction sharing mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.