This Spring Boot Java project revises the non-blocking-state-machine project to use the Spring Integration framework to handle the non-blocking processes.
The first step in using the state machine framework is to create a state transitions table as shown below. An online order processing system is considered as an example for the demo. The order processing system is assumed to have the following as the allowable state transitions:
Initial State | Pre-event | Processor | Post-event | Final State |
---|---|---|---|---|
DEFAULT | CREATE | orderProcessor() | ORDERCREATED | PAYMENTPENDING |
PAYMENTPENDING | PAY | paymentProcessor() | PAYMENTERROR | PAYMENTERROREMAILSENT |
PAYMENTERROREMAILSENT | RETRYPAY | paymentProcessor() | PAYMENTSUCCESS | PAYMENTSUCCESSEMAILSENT |
PAYMENTPENDING | PAY | paymentProcessor() | PAYMENTSUCCESS | PAYMENTSUCCESSEMAILSENT |
where the PaymentProcessor is considered a long running process and non-blocking. All other processors are assumed synchronous. The above state transitions are configured in Java enums, OrderState and OrderEvent.
Build using:
$ ./gradlew build
Run using:
$ ./gradlew bootRun
The demo includes an OrderController with three APIs to test the following scenarios:
POST http://localhost:8080/order/items
POST http://localhost:8080/orders/{orderId}/payment/{amount}
POST http://localhost:8080/orders/{orderId}/retrypayment/{amount}
The project includes a JMeter test scripts file where the above APIs can be tested.
The state transitions technique used in this Java project can be easily adapted to front-end JavaScript UI applications. Here is an example.
More information about this project is also available at this DZone article.