fix: record verified Jackson module licenses
1 file changed
tree: 3a23dc8d6f3102afc30334cac9c8a10cb6317700
  1. .github/
  2. at-sample/
  3. e2e-test/
  4. saga-annotation-sample/
  5. saga-sample/
  6. style/
  7. tcc-sample/
  8. xa-sample/
  9. .asf.yaml
  10. .gitignore
  11. .licenserc-github.yaml
  12. .licenserc.yaml
  13. .travis.yml
  14. CONTRIBUTING.md
  15. CONTRIBUTING_CN.md
  16. DISCLAIMER
  17. LICENSE
  18. NOTICE
  19. pom.xml
  20. README.md
  21. README_CN.md
README.md

Apache Seata (incubating) Java Samples

English | 简体中文

These examples show how Java applications start a distributed transaction and what happens when a participant fails. To see both outcomes in one run, start with the Spring Saga example below. To explore a particular transaction mode or framework, use the sample directory.

Apache Seata (incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.

Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.

While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. See DISCLAIMER.

Quick start: run a Saga and see it compensate

The Spring Saga sample reduces inventory and then a balance. It uses an in-memory H2 database for the state machine and connects directly to a Seata Server. For this walkthrough, use Git, Bash, JDK 17, Maven 3.9 and Seata Server 2.3.0. The server version matches the client in the sample POM.

  1. Start the transaction coordinator. Download and unpack apache-seata-2.3.0-incubating-bin.tar.gz from the Apache release archive. From the extracted distribution directory, run:

    cd seata-server
    bash bin/seata-server.sh start -h 127.0.0.1 -p 8091 -m file
    

    Wait for the server to listen on port 8091. The sample's file.conf maps my_test_tx_group to the default cluster at 127.0.0.1:8091.

  2. Build and run the sample. In a second terminal, run:

    git clone https://github.com/apache/incubator-seata-samples.git
    cd incubator-seata-samples
    mvn -f saga-sample/spring-seata-saga/pom.xml package
    java -jar saga-sample/spring-seata-saga/target/spring-seata-saga-2.3.0.jar
    
  3. Check the outcome. Look for saga transaction commit succeed. twice, once for synchronous execution and once for asynchronous execution. The final run deliberately fails the balance step. The line saga transaction compensate succeed. confirms that compensation completed. Each message includes a transaction ID (XID).

    To follow the code, open SagaTransactionStarter.java and find mockReduceBalanceFail. Follow the balance step's Catch transition to CompensationTrigger in the state machine definition. The action implementations contain the forward and compensating methods.

    When finished, press Ctrl+C if the sample is still running. From the distribution's seata-server directory, run bash bin/seata-server.sh stop to stop the local coordinator.

Sample directory

DirectoryWhat to explore
at-sample/Automatic transaction (AT) examples using JDBC, Spring, Dubbo and MyBatis. BusinessService.java shows explicit begin, commit and rollback calls. The Dubbo walkthrough covers database setup for a multi-service example.
tcc-sample/Try, Confirm and Cancel operations. In the Spring/Dubbo example, start with the consumer that initiates the transaction, then follow the participant actions in the provider. A Spring Boot/SOFA RPC variant is also available.
saga-sample/JSON state machines and compensation. Compare the single-process Spring client above with the Dubbo consumer/provider version.
saga-annotation-sample/Annotation-based compensation. Follow SagaTransactionService into the annotated actions.
xa-sample/XA transactions across Spring Boot services using Feign. The business service initiates the purchase across the storage, order and account services.
e2e-test/The builder prepares container images and test definitions, and the runner executes scenarios described by each participating sample's seata-e2e.yaml. See the English or Chinese guide.

The CI workflows build the examples and run E2E checks. The copyright template is used for source headers.

Working with another sample

  • Choose its POM. The root POM aggregates only saga-annotation-sample. For the other projects, import the chosen sample‘s POM into your IDE or pass its path to Maven with -f. Check that POM for the project’s Seata and framework versions.
  • Check its infrastructure and startup order. For example, the Spring Boot/Dubbo AT scenario uses MySQL, ZooKeeper and Seata Server. Bring up account and storage, then order, then business. The single-process Saga client above only needs the coordinator.
  • Add a sample. Place it under the matching transaction mode, name the integration for its framework stack (for example, springboot-dubbo-seata), and declare its dependencies in its own Maven project. See the contribution guide and the Seata transaction walkthrough.

For dependency licensing and the restrictions on distributing MySQL-based sample binaries, see source license checks.