Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

Build a Funds Transfer Workflow Between Two Wallets

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).

Prerequisites

Concepts

Designing

To understand the Akka concepts behind this example, see Development Process in the documentation.

Developing

This project demonstrates the use of Workflow component. For more information, see [Developing Services](https://doc. akka.io/java/index.html).

Build


Secure Repository Token

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:

  1. Use the Akka CLI's akka code token command and follow the instructions.
  2. Set up the token manually as described here.

Use Maven to build your project:

mvn compile

Run Locally

To start your service locally, run:

mvn compile exec:java

This 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.

Steps

1. Initiate transfer

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}'

2. Check transfer status

Get the current state of the transfer:

curl http://localhost:9000/transfer/1

3. Initiate transfer that requires human intervention

Start 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}'

4. Check transfer status

curl http://localhost:9000/transfer/2

5. Accept transfer

curl  -X POST http://localhost:9000/transfer/2/accept

6. Check transfer status

curl http://localhost:9000/transfer/2

Run integration tests

To run the integration tests located in src/test/java:

mvn verify

Troubleshooting

If you encounter issues, ensure that:

  • The Akka service is running and accessible on port 9000.
  • Your curl commands are formatted correctly.
  • The wallet IDs ('a' and 'b') match the ones you created.

Deploying

You can use the Akka Console to create a project and see the status of your service.

Build container image:

mvn clean install -DskipTests

Install 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 --push

Refer to Deploy and manage services for more information.

Conclusion

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.

Next steps

Now that you've built a basic transfer workflow, consider these next steps:

  1. Study the compensation mechanism: Examine TransferWorkflow.java and TransferWorkflowIntegrationTest.java to understand how compensating actions are implemented when the deposit step fails after a successful withdrawal.
  2. Explore other Akka components: Dive deeper into Akka's ecosystem to enhance your application.
  3. Explore other Akka samples: Discover more about Akka by exploring different use cases for inspiration.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages