This guide demonstrates how to create a simple workflow for transferring funds between two wallets. The
WalletService is an external service that manages wallets. The main focus of this sample is to demonstrate the
orchestration part of the Workflow component and the human in the loop aspect (accepting the transfer when the
amount is high). Other aspects like error handling, retry strategy, compensation are covered in the [documentation]
(https://doc.akka.io/sdk/workflows.html#_error_handling).
- A Akka account
- Java 21 (we recommend Eclipse Adoptium)
- Apache Maven
- Docker Engine
curlcommand-line tool
To understand the Akka concepts behind this example, see Development Process in the documentation.
This project demonstrates the use of Workflow component. For more information, see [Developing Services](https://doc. akka.io/java/index.html).
Building requires a secure repository token, which is set up as part of Akka CLI's akka code init command.
If you still need to configure your system with the token there are two additional ways:
- Use the Akka CLI's
akka code tokencommand and follow the instructions. - Set up the token manually as described here.
Use Maven to build your project:
mvn compileTo start your service locally, run:
mvn compile exec:javaThis command will start the service and create two wallets, 'a' and 'b', with an initial balance of 10000 each. The service will listen on port 9000.
Start a transfer of 10 from wallet 'a' to wallet 'b':
curl http://localhost:9000/transfer/1 \
-X POST \
--header "Content-Type: application/json" \
--data '{"from": "a", "to": "b", "amount": 10}'Get the current state of the transfer:
curl http://localhost:9000/transfer/1Start a transfer of 1001 from wallet 'a' to wallet 'b':
curl http://localhost:9000/transfer/2 \
-X POST \
--header "Content-Type: application/json" \
--data '{"from": "a", "to": "b", "amount": 1001}'curl http://localhost:9000/transfer/2curl -X POST http://localhost:9000/transfer/2/acceptcurl http://localhost:9000/transfer/2To run the integration tests located in src/test/java:
mvn verifyIf you encounter issues, ensure that:
- The Akka service is running and accessible on port 9000.
- Your
curlcommands are formatted correctly. - The wallet IDs ('a' and 'b') match the ones you created.
You can use the Akka Console to create a project and see the status of your service.
Build container image:
mvn clean install -DskipTestsInstall the akka CLI as documented in Install Akka CLI.
Deploy the service using the image tag from above mvn install:
akka service deploy transfer-workflow transfer-workflow-compensation:tag-name --pushRefer to Deploy and manage services for more information.
Congratulations, you've successfully implemented a workflow between two wallets using Akka. This project demonstrates the power of Workflow and Event Sourced Entity components in managing complex transactions.
Now that you've built a basic transfer workflow, consider these next steps:
- Study the compensation mechanism: Examine
TransferWorkflow.javaandTransferWorkflowIntegrationTest.javato understand how compensating actions are implemented when the deposit step fails after a successful withdrawal. - Explore other Akka components: Dive deeper into Akka's ecosystem to enhance your application.
- Explore other Akka samples: Discover more about Akka by exploring different use cases for inspiration.