This project shows an example of using Apache Seata for distributed transactions.
This project represents 4 services:
apache-seata-shop-serviceapache-seata-inventory-serviceapache-seata-order-serviceapache-seata-billing-service
All of these work with a Postgres database, and additionally the Shop service makes API calls to the other three, such that all of this is considered to be a single distributed transaction.
We can start the project using Docker Compose.
$ docker compose upThis will start 6 containers:
- Apache Seata
- Postgres
apache-seata-shop-serviceapache-seata-inventory-serviceapache-seata-order-serviceapache-seata-billing-service
Where apache-seaa-shop-service acts as the entrypoint into the application.
We can make HTTP calls into the application by making POST calls to the /shop/{mode} endpoint of the apache-seata-shop-service.
If the {mode} parameter is set to shop, inventory, order or billing then that service will fail during the transaction.
Anything else and the call will be successful.
For example:
$ curl -X POST localhost:8080/shop/orderWill make a request that fails within the Order service.
We can access the database used by these services using Docker:
$ docker exec -it apache-seata-postgres-1 psql --user seata seataThis opens a psql prompt inside the database, allowing us to explore the state of all the tables.