Convert Figma logo to code with AI

apache logoincubator-seata-samples

Apache Seata(incubating) Samples for Java

2,261
1,905
2,261
177

Top Related Projects

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

10,038

A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.

2,896

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

tcc-transaction是TCC型事务java实现

Quick Overview

Apache Seata (incubating) Samples is a repository containing example projects demonstrating the usage of Seata, a distributed transaction solution. These samples cover various scenarios and frameworks, helping developers understand and implement Seata in their own projects for managing distributed transactions across microservices.

Pros

  • Comprehensive collection of examples covering different use cases and integrations
  • Well-organized structure with separate directories for each sample project
  • Includes samples for popular frameworks and technologies like Spring Boot, Dubbo, and Nacos
  • Regularly updated to reflect the latest Seata features and best practices

Cons

  • Some samples may not be up-to-date with the latest Seata version
  • Documentation within individual sample projects could be more detailed
  • Limited coverage of certain advanced scenarios or edge cases
  • May require additional setup or dependencies to run certain samples

Code Examples

  1. Configuring Seata in a Spring Boot application:
@Configuration
@EnableAutoDataSourceProxy
public class SeataAutoConfig {
    @Bean
    public GlobalTransactionScanner globalTransactionScanner() {
        return new GlobalTransactionScanner("sample-service", "sample-tx-group");
    }
}
  1. Using the @GlobalTransactional annotation to mark a distributed transaction:
@GlobalTransactional
public void businessMethod() {
    // Perform multiple database operations across different services
    serviceA.doSomething();
    serviceB.doSomethingElse();
}
  1. Registering a Seata client with Nacos for service discovery:
registry {
  type = "nacos"
  nacos {
    application = "seata-server"
    serverAddr = "localhost:8848"
    namespace = ""
    cluster = "default"
  }
}

Getting Started

To run a Seata sample:

  1. Clone the repository:

    git clone https://github.com/apache/incubator-seata-samples.git
    
  2. Navigate to the desired sample project directory:

    cd incubator-seata-samples/sample-project-name
    
  3. Follow the README instructions in the sample project directory to set up dependencies and run the sample.

  4. Typically, you'll need to start the Seata server, configure the database, and run the application:

    # Start Seata server
    ./seata-server.sh
    
    # Run the sample application
    ./mvnw spring-boot:run
    

Competitor Comparisons

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

Pros of incubator-seata

  • Core project with comprehensive implementation of distributed transaction solutions
  • More extensive documentation and API references
  • Active development with frequent updates and releases

Cons of incubator-seata

  • Steeper learning curve due to complex codebase
  • May be overwhelming for users seeking simple examples or quick start guides

Code comparison

incubator-seata:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    Order order = orderService.create(userId, commodityCode, orderCount);
    if (storageService.deduct(commodityCode, orderCount)) {
        throw new RuntimeException("库存不足");
    }
    accountService.debit(userId, order.getMoney());
}

incubator-seata-samples:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    orderService.create(userId, commodityCode, orderCount);
    storageService.deduct(commodityCode, orderCount);
    accountService.debit(userId, orderCount * 5);
}

Summary

incubator-seata is the main project repository, offering a complete implementation of Seata's distributed transaction framework. It provides in-depth documentation and frequent updates but may be complex for beginners. On the other hand, incubator-seata-samples focuses on providing practical examples and use cases, making it easier for developers to understand and implement Seata in their projects. The code comparison shows that the samples repository offers simplified versions of transaction handling, which can be more approachable for newcomers to the framework.

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

Pros of incubator-seata

  • Core project with comprehensive implementation of distributed transaction solutions
  • More extensive documentation and API references
  • Active development with frequent updates and releases

Cons of incubator-seata

  • Steeper learning curve due to complex codebase
  • May be overwhelming for users seeking simple examples or quick start guides

Code comparison

incubator-seata:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    Order order = orderService.create(userId, commodityCode, orderCount);
    if (storageService.deduct(commodityCode, orderCount)) {
        throw new RuntimeException("库存不足");
    }
    accountService.debit(userId, order.getMoney());
}

incubator-seata-samples:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    orderService.create(userId, commodityCode, orderCount);
    storageService.deduct(commodityCode, orderCount);
    accountService.debit(userId, orderCount * 5);
}

Summary

incubator-seata is the main project repository, offering a complete implementation of Seata's distributed transaction framework. It provides in-depth documentation and frequent updates but may be complex for beginners. On the other hand, incubator-seata-samples focuses on providing practical examples and use cases, making it easier for developers to understand and implement Seata in their projects. The code comparison shows that the samples repository offers simplified versions of transaction handling, which can be more approachable for newcomers to the framework.

10,038

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)
  • Provides a simpler API and easier integration process
  • Offers both saga and TCC transaction patterns

Cons of dtm

  • Less mature and less widely adopted compared to Seata
  • Fewer available resources and community support
  • Limited documentation and examples for complex scenarios

Code Comparison

dtm example (Go):

err := dtmcli.TccGlobalTransaction(dtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
    resp, err := tcc.CallBranch(reqA, "localhost:8081/api/TransOut", "localhost:8081/api/TransOutConfirm", "localhost:8081/api/TransOutCancel")
    if err != nil {
        return nil, err
    }
    return tcc.CallBranch(reqB, "localhost:8081/api/TransIn", "localhost:8081/api/TransInConfirm", "localhost:8081/api/TransInCancel")
})

Seata example (Java):

@GlobalTransactional
public void transfer(String fromAccount, String toAccount, double amount) {
    accountService.debit(fromAccount, amount);
    accountService.credit(toAccount, amount);
}

Both dtm and Seata-samples provide distributed transaction solutions, but they differ in implementation and supported languages. dtm offers a more language-agnostic approach with simpler integration, while Seata-samples focuses on Java ecosystem with deeper integration into popular frameworks.

2,896

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

  • Lightweight and focused specifically on TCC (Try-Confirm-Cancel) transaction model
  • Simpler implementation for projects that only need TCC support
  • Potentially easier to integrate into existing projects due to its focused nature

Cons of ByteTCC

  • Less comprehensive feature set compared to Seata Samples
  • Smaller community and potentially less active development
  • May lack some of the more advanced distributed transaction scenarios covered by Seata

Code Comparison

ByteTCC example:

@Compensable(confirmMethod = "confirmIncrease", cancelMethod = "cancelIncrease")
public void increaseAmount(String accountId, double amount) {
    // Try phase logic
}

Seata Samples example:

@GlobalTransactional
public void purchase(String userId, String commodityCode, int orderCount) {
    // Business logic with multiple service calls
}

Summary

ByteTCC is a more focused solution for TCC transactions, while Seata Samples offers a broader range of distributed transaction patterns. ByteTCC may be easier to implement for specific TCC use cases, but Seata Samples provides more comprehensive features for various distributed transaction scenarios. The choice between the two depends on the project's specific requirements and the desired level of transaction management complexity.

tcc-transaction是TCC型事务java实现

Pros of tcc-transaction

  • Lightweight and focused specifically on TCC (Try-Confirm-Cancel) transaction patterns
  • Simpler implementation for projects that only need TCC functionality
  • More mature project with longer development history

Cons of tcc-transaction

  • Limited to TCC pattern, while Seata samples cover multiple transaction modes
  • Less active development and community support compared to Seata
  • Fewer integration examples with popular frameworks and databases

Code Comparison

tcc-transaction:

@Compensable(confirmMethod = "confirmOrderCreation", cancelMethod = "cancelOrderCreation")
public String createOrder(Order order) {
    // Order creation logic
}

Seata samples:

@GlobalTransactional
public void createOrder(String userId, String commodityCode, int orderCount) {
    Order order = new Order();
    // Order creation logic
    orderMapper.insert(order);
}

The tcc-transaction example uses specific annotations for TCC methods, while Seata samples use a more generic @GlobalTransactional annotation. Seata's approach is more flexible but may require additional configuration for TCC-specific scenarios.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

samples code specification

Directory Structure

The first and second levels are more of a directory

Top level: seata-samples

Second layer: at-sample, tcc-sample, saga-sample, xa-sample

Third floor, The third layer is the specific sample and the naming convention is as follows:

naming

naming with framework: spring-nacos-seata, springboot-naocs-zk-seata ...

dependency

pom: The dependencies of each sample should be independent and should not depend on the dependencies of the parent pom of seata samples.

samples transaction model

https://seata.apache.org/docs/user/quickstart/

start sequence

1、account

2、storage

3、order

4、business