This demo simulates a booking application including three services:
You will need:
You can run the demo using either docker compose or executable files.
run the following command to create docker images in saga project root folder.
mvn clean package -DskipTests -Pdocker -Pdemo
start the whole application up(including alpha server and three demo services)
./saga-demo.sh up
Note: If you prefer to use MySQL as alpha's backend database, you need to try the following steps instead:
mysql-connector-java
in alpha/alpha-server/pom.xml
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
docker rmi -f $(docker images | grep alpha-server | awk '{print $3}')
mvn package -DskipTests -Pdocker -Pdemo
saga-demo/booking
with the following command./saga-demo.sh up-mysql
Note: If you want start alpha server and demon services separately, you can try the following steps:
./saga-demo.sh up-alpha
./saga-demo.sh up-demo
stop application
./saga-demo.sh down
run the following command to generate executable alpha server jar in alpha/alpha-server/target/saga/alpha-server-${saga_version}-exec.jar
.
mvn clean package -DskipTests -Pdemo
follow the instructions in the How to run section in User Guide to run postgreSQL and alpha server.
start application up
saga-demo/booking/hotel/target/saga
.java -Dserver.port=8081 -Dalpha.cluster.address=${alpha_address}:8080 -jar hotel-${saga_version}-exec.jar
saga-demo/booking/car/target/saga
.java -Dserver.port=8082 -Dalpha.cluster.address=${alpha_address}:8080 -jar car-${saga_version}-exec.jar
saga-demo/booking/booking/target/saga
.java -Dserver.port=8083 -Dalpha.cluster.address=${alpha_address}:8080 -Dcar.service.address=${host_address}:8082 -Dhotel.service.address=${host_address}:8081 -jar booking-${saga_version}-exec.jar
curl -X POST http://${host_address}:8083/booking/test/2/2
Check the hotel booking status with
curl http://${host_address}:8081/bookings
Check the car booking status with
curl http://${host_address}:8082/bookings
curl -X POST http://${host_address}:8083/booking/test/3/2
Check the hotel booking status with
curl http://${host_address}:8081/bookings
Check the car booking status with
curl http://${host_address}:8082/bookings
The second car booking will be marked with cancel:true
Open a browser with URL http://127.0.0.1:8083, You will get a html page. You can use this page to invoke test cases, and then get results.
Note transactions and compensations implemented by services must be idempotent.