In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "PHP collaboration client v0.1 beta version of what are the new features", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "PHP collaboration client v0.1 beta version of what are the new features" bar!
Introduction
Dtm/dtm-client is the PHP client of the distributed transaction manager DTM, which supports the distributed transaction mode of TCC mode, Saga mode and two-phase message mode, and communicates with DTM Server with HTTP protocol or gRPC protocol respectively. The client can run safely in PHP-FPM and Swoole protocol environment, and it is easier to support Hyperf.
About DTM
DTM is an open source distributed transaction manager based on Go language, which provides the powerful function of combining transactions across languages and storage engines. DTM elegantly solves the problems of idempotency, null compensation, suspension and other distributed transaction problems, and also provides a distributed transaction solution that is easy to use, high performance and easy to scale horizontally.
Bright spot
Very easy to use.
Zero configuration startup service, which provides a very simple HTTP interface, greatly reducing the difficulty of getting started with distributed transactions
Cross-language
It is suitable for companies with multi-language stacks. Convenient for Go, Python, PHP, NodeJs, Ruby, C # and other languages.
Easy to use
Developers no longer worry about suspension, empty compensation, power and other problems, and pioneer sub-transaction barrier technology to deal with it.
Easy to deploy and scale
Relying only on MySQL/Redis, it is easy to deploy, easy to cluster and easy to scale horizontally.
Support for multiple distributed transaction protocols
TCC, SAGA, XA, two-phase message, one-stop solution to multiple distributed transaction problems
Contrast
In non-Java languages, there is no mature distributed transaction manager other than DTM, so here we compare DTM with Seata, the most mature open source project in Java:
Feature DTMSEATA remarks support languages Go, C #, Java, Python, PHP... JavaDTM can easily connect to a new language storage engine to support database, Redis, Mongo and other databases.
Exception handling subtransaction barrier automatic handling manual processing DTM solves idempotent, suspension, null compensation SAGA transactions are very easy to use complex state machines
Two-phase message ✓✗ Minimalist message final consistency Architecture TCC transaction ✓✓
XA transaction ✓✓
XA ✓ AT is recommended for AT transactions, similar to XA, but with dirty rollback single service multiple data source ✓✗
Communication protocols such as HTTP, gRPCDubbo and other protocols DTM are more cloud-friendly and star-friendly.
DTM released version 0.1 from 2021-06-04 and developed rapidly.
Judging from the features compared above, DTM has great advantages in many ways. If you consider multi-language support, multi-storage engine support, then DTM is undoubtedly your first choice.
Installation
It is very convenient to install dtm-client through Composer
Composer require dtm/dtm-client
Don't forget to start DTM Server when using it.
Configuration profil
If you are using the Hyperf framework, after installing the components, you can publish the configuration file to. / config/autoload/dtm.php with the following vendor:publish command
Php bin/hyperf.php vendor:publish dtm/dtm-client
If you are using in a non-Hyperf framework, copy the. / vendor/dtm/dtm-client/publish/dtm.php file to the corresponding configuration directory.
Use DtmClient\ Constants\ Protocol;use DtmClient\ Constants\ DbType Return [/ / the protocol of communication between client and DTM Server Addresses that support Protocol::HTTP and Protocol::GRPC 'protocol' = > Protocol::HTTP, / / DTM Server' server' = > '127.0.0.1', and ports of / / DTM Server 'port' = > [' http' = > 36789, 'grpc' = > 36790,] / / Sub-transaction barrier configuration 'barrier' = > [/ / sub-transaction barrier configuration in DB mode' db' = > ['type' = > DbType::MySQL], / / sub-transaction barrier configuration in Redis mode' redis' = > [/ / timeout of sub-transaction barrier records' expire_seconds' = > 7 * 86400 ], / / the class that applies the sub-transaction barrier under the non-Hyperf framework 'apply' = > [], / / the general configuration of the Guzzle client under the HTTP protocol' guzzle' = > ['options' = > [],] Configure middleware
Before you use it, you need to configure DtmClient\ Middleware\ DtmMiddleware middleware as the global middleware for Server, which supports the PSR-15 specification and can be applied to various frameworks that support it.
Middleware configuration in Hyperf can be seen in the Hyperf documentation-Middleware chapter.
Use
The use of dtm-client is very simple, we provide a sample project dtm-php/dtm-sample to help you better understand and debug.
Before using this component, it is also strongly recommended that you read the official DTM documentation for a more detailed understanding.
TCC mode
TCC pattern is a very popular flexible transaction solution, which consists of the acronyms of the three words Try-Confirm-Cancel to form the concept of TCC, which was first proposed by Pat Helland in a paper called "Life beyond Distributed Transactions:an Apostate's Opinion" published in 2007.
Three stages of TCC
Try phase: try to execute, complete all business checks (consistency), reserve necessary business resources (quasi-isolation)
Confirm phase: if the Try of all branches is successful, go to the Confirm phase. Confirm really executes the business, does not make any business inspection, and only uses the business resources reserved during the Try phase.
Cancel phase: if one of the Try of all branches fails, then go to the Cancel phase. Cancel releases the business resources reserved during the Try phase.
If we want to conduct a business similar to inter-bank transfer, TransOut and TransIn respectively in different microservices, the typical timing diagram of a successfully completed TCC transaction is as follows:
Code example
The following shows how to use it in the Hyperf framework, similar to other frameworks
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.