Download the PHP package vhnnnbj/laravel-rt without Composer
On this page you can find all versions of the php package vhnnnbj/laravel-rt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vhnnnbj/laravel-rt
More information about vhnnnbj/laravel-rt
Files in vhnnnbj/laravel-rt
Package laravel-rt
Short Description distributed transaction for call remote api service
License MIT
Informations about the package laravel-rt
laravel-reset-transaction
RT (reset transaction) mode can be as distributed transaction for call remote api service
Overview
Install the version between laravel5.5-laravel8, and then install the composer package
First create order, storage, account 3 mysql database instances, 3 controllers, 3 models, add testsuite Transaction to phpunit.xml, and then start the web server. These operations only need to execute the following commands to complete all
Open another terminal and start the web server with port 8001
Finally run the test script ./vendor/bin/phpunit --testsuite=Transaction --filter=ServiceTest
The running results are shown below, and the 3 examples have passed the test.
Feature
- Out of the box, no need to refactor the code of the original project, consistent with the mysql transaction writing, simple and easy to use.
- Comply with the two-stage commit protocol, which is a strong consistency transaction. Under high concurrency, it supports the isolation level of read committed transactions, and the data consistency is 100% close to mysql xa.
- Since the transaction is split into multiple and become several small transactions, the stress test finds that there are fewer deadlocks than mysql ordinary transactions.
- Support distributed transaction nesting, consistent with savepoint.
- Support to avoid the problem of dirty data caused by the concurrency of different business codes.
- The service-oriented interface of the http protocol is supported by default. If you want to support other protocols, you need to rewrite the middleware.
- Support for nested distributed transactions of sub-services (world's first).
- Support services, mixed nesting of local transactions and distributed transactions (the world's first)
- Support 3 retries over time, repeated requests to ensure idempotence
- Support go, java language (under development)
Principle
You will know the operation of archiving and reading files after watching the movie "Edge of Tomorrow". This distributed transaction component imitates the principle of the "Edge of Tomorrow" movie. Reset means to reset, that is, read the file at the beginning of each request for the basic service, and then continue the subsequent operations. At the end, all operations are rolled back and archived, and finally One step commit successfully executes all the archives. The whole process is to comply with the two-stage submission agreement, first prepare, and finally commit.
Taking the scenario where user A transfers 100 yuan to user B's China Merchants Bank account with a China Merchants Bank card as an example, the following flowchart is drawn. After the reset distributed transaction is turned on in the right picture, there are 4 more requests than the left picture. What request 4 does is what was done before request 1-3, and then come back to the original point and start again, finally submit the transaction, and end the transfer process.
Support sub-service nested distributed transaction (world's first)
A world-class problem: A service commit->B service rollback->C service commit->D service commit sql. In this scenario, ABCD are all different databases. How can I make A service submit B service and roll back? What about all operations of the C service and D service?
Neither seata nor go-dtm can solve this problem. The key point to solve the problem is that the C service and D service must be submitted falsely, and cannot be submitted truly. If they are submitted, they will be unable to recover.
What are the benefits of implementing nested distributed transactions that support sub-services? You can make A service a service of others, and it can be nested in any layer of the link arbitrarily. Breaking the previous shackles: Service A must be a root service, and if Service A is to become a sub-service, the code must be changed. If the RT mode is used, service A can become someone else's service without modifying the code.
How to use
Take the vendor/windawake/laravel-reset-transaction/tests/ServiceTest.php
file as an example
Contact
Scan code into wechat group. I hope that more friends will learn from each other and study the knowledge of distributed transactions together.