This application demonstrates usage of Narayana inside of a Spring Boot application running on OpenShift.
Standard Narayan Spring Boot application has its own transaction and recovery managers. However, because of volatile OpenShift pods it is not safe to have such a setup. In a scenario where pod is killed in a middle of a transaction, there would be impossible to recover uncompleted transaction. For that reason, this example extends current Narayana integration and requires application to run on an OpenShift stateful set. As a result, only a first pod will run recovery manager which will be responsible for recovering transactions of all other pods. It will access their transaction records from JDBC object store configured in a separate PostgreSQL deployment.
- Deploy database
oc new-app \
-p POSTGRESQL_USER=narayana \
-p POSTGRESQL_PASSWORD=narayana \
-p POSTGRESQL_DATABASE=narayana \
-p DATABASE_SERVICE_NAME=narayana-database \
--name=narayana-database \
--template=postgresql-persistent
- Set environment variable
POSTGRESQL_MAX_PREPARED_TRANSACTIONS=100
- Deploy this application to OpenShift
mvn clean fabric8:deploy -Dfabric8.mode=kubernetes
- Scale-up application
oc scale statefulsets spring-boot-narayana-stateful-set-example --replicas=2
- Get entries
curl http://spring-boot-narayana-stateful-set-example-myproject.192.168.64.3.nip.io/
- Create new entry
curl -X POST http://spring-boot-narayana-stateful-set-example-myproject.192.168.64.3.nip.io/?entry=hello
- Crash when creating entry
curl -X POST http://spring-boot-narayana-stateful-set-example-myproject.192.168.64.3.nip.io/?entry=kill
New entry 'kill' should appear after pod is restarted and recovery completes. Try killing different containers (requests are routed interchangeably between two pods).
oc delete statefulsets/spring-boot-narayana-stateful-set-example
- Open PostgreSQL pod terminal
- Connect (password: narayana)
psql -h narayana-database -U narayana
- Select object store entries
select * from actionjbosststxtable;
- Open PostgreSQL pod terminal
- Connect (password: narayana)
psql -h narayana-database -U narayana
- Select object store entries
delete from actionjbosststxtable;