Top Related Projects
A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
ByteTCC is a distributed transaction manager based on the TCC(Try/Confirm/Cancel) mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteTCC/wiki
Quick Overview
The changmingxie/tcc-transaction
project is a Java implementation of the Transactional Compensation Consistency (TCC) pattern, which is a distributed transaction management framework. It provides a way to handle complex business transactions that span multiple services or systems, ensuring data consistency and reliability.
Pros
- Distributed Transaction Management: The project offers a robust solution for managing distributed transactions, making it suitable for complex, microservices-based architectures.
- Customizable Compensation Logic: Developers can easily define their own compensation logic for each business operation, allowing for flexible and tailored transaction handling.
- Annotation-based Configuration: The project uses annotations to simplify the configuration and integration of the TCC framework, reducing boilerplate code.
- Extensible Design: The project's modular design allows for easy integration with various data sources and transaction managers, making it adaptable to different use cases.
Cons
- Learning Curve: Developers may need to invest time in understanding the TCC pattern and how to properly integrate it into their application architecture.
- Potential Performance Impact: The overhead of the TCC framework may impact the overall performance of the application, especially for high-throughput scenarios.
- Limited Documentation: The project's documentation could be more comprehensive, making it challenging for new users to get started quickly.
- Lack of Active Maintenance: The project appears to have limited active maintenance, which may raise concerns about long-term support and updates.
Code Examples
Defining a TCC-based Service Method
@Transactional(type = TransactionType.TCC)
public void transferMoney(String from, String to, BigDecimal amount) {
// Try phase: Deduct money from the "from" account
accountRepository.deductBalance(from, amount);
// Confirm phase: Add money to the "to" account
accountRepository.addBalance(to, amount);
}
This example demonstrates how to define a TCC-based service method using the project's annotations. The @Transactional
annotation specifies the transaction type as TCC, and the method implementation includes the try and confirm phases.
Implementing Compensation Logic
@Component
public class AccountTransferCompensation implements Compensable {
@Override
public void compensate(TransactionContext context) {
// Compensation logic: Revert the money transfer
String from = context.getActionContext().getParameter("from");
String to = context.getActionContext().getParameter("to");
BigDecimal amount = context.getActionContext().getParameter("amount");
accountRepository.addBalance(from, amount);
accountRepository.deductBalance(to, amount);
}
}
This example shows how to implement the compensation logic for the money transfer operation. The AccountTransferCompensation
class implements the Compensable
interface and provides the necessary logic to revert the money transfer in case of a failure.
Configuring the TCC Transaction Manager
@Configuration
public class TccTransactionConfiguration {
@Bean
public TransactionManager transactionManager(List<Compensable> compensables) {
TccTransactionManager transactionManager = new TccTransactionManager();
transactionManager.setCompensables(compensables);
return transactionManager;
}
}
This example demonstrates how to configure the TCC transaction manager in the application's Spring configuration. The TccTransactionConfiguration
class sets up the TccTransactionManager
and injects the list of Compensable
implementations.
Getting Started
To get started with the changmingxie/tcc-transaction
project, follow these steps:
-
Add the project dependency to your Java application's build configuration (e.g., Maven or Gradle):
<dependency> <groupId>com.github.changmingxie</groupId> <artifactId>tcc-transaction</artifactId> <version>2.1.2</version> </dependency>
-
Configure the TCC transaction manager in your application's Spring configuration:
@Configuration public class TccTransactionConfiguration { @Bean public TransactionManager transactionManager(List<Compens
Competitor Comparisons
A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.
Pros of dtm
- Supports multiple programming languages (Go, Java, Python, PHP, Node.js)
- Offers various distributed transaction patterns (2PC, Saga, TCC, XA)
- Provides a simple API and easy integration
Cons of dtm
- Relatively newer project with less production usage
- Documentation may not be as comprehensive as tcc-transaction
Code Comparison
dtm (Go):
saga := dtmcli.NewSaga(DtmServer, gid).
Add(busi.Busi+"/TransOut", busi.Busi+"/TransOutCompensate", req).
Add(busi.Busi+"/TransIn", busi.Busi+"/TransInCompensate", req)
err := saga.Submit()
tcc-transaction (Java):
@Compensable(confirmMethod = "confirmOrderCreation", cancelMethod = "cancelOrderCreation")
public String createOrder(Order order) {
// Business logic
}
Both projects aim to solve distributed transaction problems, but dtm offers a more versatile solution with support for multiple languages and transaction patterns. tcc-transaction focuses specifically on the TCC (Try-Confirm-Cancel) pattern and is primarily for Java applications. dtm's API appears more straightforward, while tcc-transaction relies on annotations for transaction management. The choice between the two depends on specific project requirements, language preferences, and desired transaction patterns.
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
Pros of Seata
- More comprehensive distributed transaction solution, supporting multiple transaction modes (AT, TCC, SAGA, XA)
- Better integration with popular frameworks and cloud-native environments
- Larger community support and active development as an Apache Incubator project
Cons of Seata
- Higher complexity and steeper learning curve due to its extensive features
- Potentially higher overhead for simpler use cases compared to TCC-Transaction
Code Comparison
TCC-Transaction:
@Compensable(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public void tryMethod() {
// Business logic
}
Seata:
@GlobalTransactional
public void businessMethod() {
// Business logic
}
Key Differences
- TCC-Transaction focuses solely on TCC (Try-Confirm-Cancel) pattern, while Seata offers multiple transaction modes
- Seata provides more built-in integrations with various frameworks and databases
- TCC-Transaction has a simpler API and is easier to implement for TCC-specific use cases
- Seata offers more advanced features like transaction coordination and global locking
Use Case Recommendations
- Choose TCC-Transaction for simpler projects primarily requiring TCC pattern
- Opt for Seata in complex distributed systems needing multiple transaction modes and extensive integrations
ByteTCC is a distributed transaction manager based on the TCC(Try/Confirm/Cancel) mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteTCC/wiki
Pros of ByteTCC
- More comprehensive documentation and examples
- Better support for multiple databases and messaging systems
- More active development and community engagement
Cons of ByteTCC
- Slightly more complex configuration process
- Less integration with popular frameworks like Spring Boot
- Steeper learning curve for beginners
Code Comparison
ByteTCC:
@Compensable(confirmMethod = "confirmOrder", cancelMethod = "cancelOrder")
public void createOrder(Order order) {
// Business logic
}
tcc-transaction:
@Compensable(confirmMethod = "confirmCreateOrder", cancelMethod = "cancelCreateOrder")
public void createOrder(Order order) {
// Business logic
}
Both projects use similar annotations for defining compensable methods, but ByteTCC offers more flexibility in method naming conventions.
Summary
ByteTCC and tcc-transaction are both TCC (Try-Confirm-Cancel) transaction frameworks for distributed systems. ByteTCC offers more comprehensive features and better support for various databases and messaging systems, but it may be more complex to set up and use. tcc-transaction, on the other hand, is simpler and integrates better with Spring Boot, making it a good choice for projects already using the Spring ecosystem. The choice between the two depends on the specific requirements of your project and your team's familiarity with distributed transaction concepts.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
TCC-TRANSACTION
TCC-TRANSACTIONæ¯ä»ä¹
TCC-TRANSACTIONæ¯ä¸æ¬¾å¼æºçå¾®æå¡æ¶æä¸çTCCååå¸å¼äºå¡è§£å³æ¹æ¡ï¼è´åäºæä¾é«æ§è½åç®åæç¨çåå¸å¼äºå¡æå¡ã
- Try: å°è¯æ§è¡ä¸å¡ï¼å®æææä¸å¡æ£æ¥ï¼ä¸è´æ§ï¼ï¼é¢çå¿ é¡»ä¸å¡èµæºï¼åé离æ§ï¼
- Confirm: 确认æ§è¡ä¸å¡ï¼ä¸ä½ä»»ä½ä¸å¡æ£æ¥ï¼åªä½¿ç¨Tryé¶æ®µé¢ççä¸å¡èµæºï¼æ»¡è¶³å¹çæ§
- Cancel: åæ¶æ§è¡ä¸å¡ï¼éæ¾Tryé¶æ®µé¢ççä¸å¡èµæºï¼æ»¡è¶³å¹çæ§
å¾®æå¡æ¶æä¸åå¸å¼äºå¡é®é¢
éçä¼ ç»çåä½æ¶çæå¾®æå¡åï¼åæ¬åä½æ¶æä¸ä¸å模åï¼è¢«æå为è¥å¹²ä¸ªåè½ç®åãæ¾è¦åçæå¡ã
ç³»ç»å¾®æå¡ååï¼å
é¨å¯è½éè¦è°ç¨å¤ä¸ªæå¡å¹¶æä½å¤ä¸ªæ°æ®åºå®ç°ï¼æå¡è°ç¨çåå¸å¼äºå¡é®é¢åçé常çªåºã
æ¯å¦æ¯ä»é款åºæ¯éè¦ä»ååè´¦æ¹éåå¹³å°æ¶çæ·(éåè´¦)ï¼åéè¿ç»ä»æ¬¾æ¹ãå ¶ä¸**éåè´¦**é¶æ®µï¼ æ¶åä»å¤ä¸ªåè´¦æ¹(å家1æ¶çæ·ï¼å家2æ¶çæ·ï¼å家3æ¶çæ·ï¼å¹³å°æç»è´¹è´¦æ·)æ£æ¬¾ï¼è¿äºè´¦æ·åå¸å¨ä¸åæ°æ®åºï¼ æ¯å¦å家3æ¶çæ·æ£æ¬¾å¤±è´¥ï¼å ¶ä»æåæ£æ¬¾éè¦åæ»ï¼è¿ééè¦åå¸å¼äºå¡ä¿è¯ä¸è´æ§ã
å¦ä½è§£å³
å¦ä½è§£å³ä¸é¢**éåè´¦**ä¸åå¸å¼äºå¡é®é¢å¢ï¼ éæ©ä½¿ç¨tcc-transactionæ¡æ¶ï¼æ§è¡æµç¨å¦ä¸ï¼
- Try:
å家1æ¶çæ·->å»ç»åè´¦éé¢
å家2æ¶çæ·->å»ç»åè´¦éé¢
å家3æ¶çæ·->å»ç»åè´¦éé¢
å¹³å°æç»è´¹->å»ç»æç»è´¹ - Tryæå => Confirm:
å家1æ¶çæ·->æ£é¤åè´¦éé¢
å家2æ¶çæ·->æ£é¤åè´¦éé¢
å家3æ¶çæ·->æ£é¤åè´¦éé¢
å¹³å°æç»è´¹->æ£é¤æç»è´¹
å¹³å°æ¶çæ·-> å¢å éé¢(æ»åè´¦éé¢+æç»è´¹) - Try失败 => Cancel:
å家1æ¶çæ·->解å»åè´¦éé¢
å家2æ¶çæ·->解å»åè´¦éé¢
å家3æ¶çæ·->解å»åè´¦éé¢
å¹³å°æç»è´¹->解å»æç»è´¹
å·¥ä½åç
第ä¸é¶æ®µï¼ä¸»ä¸å¡æå¡åå«è°ç¨ææä»ä¸å¡ç try æä½ï¼å¹¶å¨æ´»å¨ç®¡çå¨ä¸ç»è®°ææä»ä¸å¡æå¡ãå½ææä»ä¸å¡æå¡ç try æä½é½è°ç¨æåæè
æ个ä»ä¸å¡æå¡ç try æä½å¤±è´¥ï¼è¿å
¥ç¬¬äºé¶æ®µã
第äºé¶æ®µï¼æ´»å¨ç®¡çå¨æ ¹æ®ç¬¬ä¸é¶æ®µçæ§è¡ç»ææ¥æ§è¡ confirm æ cancel æä½ã
å¦æ第ä¸é¶æ®µææ try æä½é½æåï¼åæ´»å¨ç®¡çå¨è°ç¨ææä»ä¸å¡æ´»å¨ç confirmæä½ãå¦åè°ç¨ææä»ä¸å¡æå¡ç cancel æä½ã
éè¦æ³¨æçæ¯ç¬¬äºé¶æ®µ confirm æ cancel æä½æ¬èº«ä¹æ¯æ»¡è¶³æç»ä¸è´æ§çè¿ç¨ï¼å¨è°ç¨ confirm æ cancel çæ¶åä¹å¯è½å 为æç§åå ï¼æ¯å¦ç½ç»ï¼å¯¼è´è°ç¨å¤±è´¥ï¼æ以éè¦æ´»å¨ç®¡çæ¯æéè¯çè½åï¼åæ¶è¿ä¹å°±è¦æ±
confirm å cancel æä½å
·æå¹çæ§ã
å¿«éå¼å§
å®ç½
å¿«éå¼å§
ææ°å¯ç¨çæ¬2.x
常è§é®é¢
讨论群
ééæ«ç å ¥ç¾¤
Top Related Projects
A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.
:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
ByteTCC is a distributed transaction manager based on the TCC(Try/Confirm/Cancel) mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteTCC/wiki
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot