Distributed transaction middleware TCC-Transaction source code analysis-debugging environment construction

Distributed transaction middleware TCC-Transaction source code analysis-debugging environment construction

"Dubbo Implementation Principle and Source Code Analysis-A Collection of Excellent Works" "Netty Implementation Principle and Source Code Analysis-A Collection of Excellent Products"
"Spring Implementation Principles and Source Code Analysis-Collection of Excellent Works" "MyBatis implementation principle and source code analysis-a collection of excellent products"
"Spring MVC Implementation Principle and Source Code Analysis-A Collection of Excellent Products" "Database Entity Design Collection"
"Spring Boot Implementation Principles and Source Code Analysis-A Collection of Excellent Products" "Java Interview Questions + Java Study Guide"

Abstract: Original source www.iocoder.cn/TCC-Transac... "Taro Source" welcome to reprint, keep the abstract, thank you!

This article is mainly based on the official version of TCC-Transaction 1.2.3.3


Follow the WeChat public account : [Taro Source] There are benefits:

  1. RocketMQ/MyCAT/Sharding-JDBC all source code analysis article list
  2. RocketMQ/MyCAT/Sharding-JDBC Chinese annotation source code GitHub address
  3. Your source for questions about each message are to get serious reply. You can ask even if you don't know how to read the source code .
  4. New source code analysis articles will be notified in real time . Update about one article every week .
  5. Serious source code exchange WeChat group.

1. Rely on tools

  • Maven
  • Git
  • JDK
  • MySQL
  • IntelliJ IDEA

2. Source code pull

From the official warehouse github.com/changmingxi...out Fork your own warehouse. why wouldFork ? Now that we start to read and debug the source code, we may write some comments. With our own warehouse, we can submit freely.

Using IntelliJ IDEAfrom Forkout of the warehouse pull code. After the pull is complete,Maven dependency package will be downloaded. It may take some time to wait patiently.

Based on the master-1.2.xbranches.

3. Initialize the database

The official provides two demo project examples:

  • tcc-transaction-dubbo-sample
  • tcc-transaction-http-sample

Considering that not all students have used the Dubbo service framework, we take the tcc-transaction-http-sample project as an example.

Narrator, be sure to note that it is the tcc-transaction-http-sample project, so don t use it wrong! ! !

Open the tcc-transaction-http-sample/src/main/dbscripts directory, there are four SQL script files:

  • create_db_cap.sql : Tcc-transaction-http-capital project database initialization script.
  • create_db_ord.sql : Tcc-transaction-http-order project database initialization script.
  • create_db_red.sql : Tcc-transaction-http-redpacket project database initialization script.
  • create_db_tcc.sql: Tcc-transaction bottom database initialization script.

The author uses Navicat to execute database scripts. The usage method is: Navicat menu Connection -> Execute SQL File, select script files, and execute them one by one.

Currently the database script does not use the USEstatement to select the corresponding database, each script needs to be added. With create_db_cap.sqlexample child:

CREATE DATABASE `tcc_cap`/*!40100 DEFAULT CHARACTER SET utf8 */;
--   USE
USE `tcc_cap`;
 

4. Start the capital project

  1. Modify the project under the jdbc.propertiesfile, fill in the address into your database .
  2. Use IDEA to configure Tomcat to start. Note here:

    //appcontext-service-provider.xml
    <bean id="httpServer"
         class="org.springframework.remoting.support.SimpleHttpServerFactoryBean">
       <property name="contexts">
           <util:map>
               <entry key="/remoting/CapitalTradeOrderService" value-ref="capitalTradeOrderServiceExporter"/>
               <entry key="/remoting/CapitalAccountService" value-ref="capitalAccountServiceExporter"/>
           </util:map>
       </property>
       <property name="port" value="8081"/>
    </bean>
     
    • Port 8081 is opened by default to provide interface services. Therefore, 8081 cannot be used for the Tomcat port to avoid conflicts. For example, I use 18081.
  3. Visit http://127.0.0.1:18081/and see "hello tcc transacton http sample capital", which means that the project is started. 18081Fill in the Tomcat port for you.

5. Start the redpacket project

Same as tcc-transaction-http-capital project.

6. Start the order project

  1. Modify the project under the jdbc.propertiesfile, fill in the address into your database .
  2. Use IDEA to configure Tomcat to start.
  3. Visit http://127.0.0.1:8080/and see "sample description...", which means that the project is started. 8080Fill in the Tomcat port for you.
  4. Click [Product List Link] -> [Buy] -> [Pay], if you see "payment successful" or "payment failed", congratulations , you have successfully built your debugging environment. Start playing happily.

666. Easter eggs

Setting up a debugging environment is the first step in reading the source code. If you encounter a situation where the build fails, please leave a message on the author's official account ( Taro Source Code ). I will give you 1: Advanced (1 gay ) support.

In addition, this is a series of articles. This series updates TCC-Transaction, and the next series updates ByteTCC. Hey, isn't it? !

Fellow Daoists, get in the car and share a wave of friends!