This guide demonstrates how to create a simple workflow for transferring funds between two wallets.
Used for code snippets in the Workflow documentation.
- A Akka account
- Java 21 (we recommend Eclipse Adoptium)
- Apache Maven
- Docker Engine
curlcommand-line tool- A Secure Repository Token
To understand the Akka concepts behind this example, see Development Process in the documentation.
This project demonstrates the use of Workflow and Event Sourced Entity components. For more information, see Developing Services.
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 your Akka service and a companion Akka Runtime.
Create wallet 'a' with an initial balance of 100:
curl -i -X POST http://localhost:9000/wallet/a/create/100Create wallet 'b' with an initial balance of 100:
curl -i -X POST http://localhost:9000/wallet/b/create/100Attempt to withdraw 110 from wallet 'a':
curl -i -X POST http://localhost:9000/wallet/a/withdraw/110Note: This request results in an HTTP 400 Bad Request response due to insufficient balance in wallet 'a'.
Get wallet 'a' current balance:
curl http://localhost:9000/wallet/aGet wallet 'b' current balance:
curl http://localhost:9000/wallet/bStart 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/1curl http://localhost:9000/transfers/completedTo 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: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:
- Explore other Akka components: Dive deeper into Akka's ecosystem to enhance your application.
- Expand the service: Explore other Akka components to enhance your application with additional features.
- Explore other Akka samples: Discover more about Akka by exploring different use cases for inspiration.