Skip to content

About

A funds transfer workflow between two wallets

Resources

Stars

0 stars

Watchers

4 watching

Forks

Latest commit

 

History

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

Used for code snippets in the Workflow documentation.

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 and Event Sourced Entity components. For more information, see Developing Services.

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 your Akka service and a companion Akka Runtime.

Steps

1. Create wallet 'a'

Create wallet 'a' with an initial balance of 100:

curl -i -X POST http://localhost:9000/wallet/a/create/100

2. Create wallet 'b'

Create wallet 'b' with an initial balance of 100:

curl -i -X POST http://localhost:9000/wallet/b/create/100

3. Withdraw from wallet 'a'

Attempt to withdraw 110 from wallet 'a':

curl -i -X POST http://localhost:9000/wallet/a/withdraw/110

Note: This request results in an HTTP 400 Bad Request response due to insufficient balance in wallet 'a'.

4. Check wallet balances

Get wallet 'a' current balance:

curl http://localhost:9000/wallet/a

Get wallet 'b' current balance:

curl http://localhost:9000/wallet/b

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

6. Check transfer status

Get the current state of the transfer:

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

6. Check all completed transfers

curl http://localhost:9000/transfers/completed

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: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. Explore other Akka components: Dive deeper into Akka's ecosystem to enhance your application.
  2. Expand the service: Explore other Akka components to enhance your application with additional features.
  3. Explore other Akka samples: Discover more about Akka by exploring different use cases for inspiration.

About

A funds transfer workflow between two wallets

Resources

Stars

0 stars

Watchers

4 watching

Forks

Used by

Contributors

Languages