Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build a Shopping Cart

The section Build your first application shows how to build this Shopping Cart service step by step.

Prerequisites

Concepts

Designing

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

Developing

Please follow Build your first application to understand the details of this service implementation.

Building


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

Running Locally

To start your Akka service locally, run:

mvn compile exec:java

Exercising the service

With your Akka service running, any defined endpoints should be available at http://localhost:9000.

  • Add an item
curl -i -XPUT -H "Content-Type: application/json" localhost:9000/carts/123/item -d '
{"productId":"akka-tshirt", "name":"Akka Tshirt", "quantity": 10}'
  • Get cart state
curl localhost:9000/carts/123
  • Remove an item
curl -i -XDELETE -H "Content-Type: application/json" localhost:9000/carts/123/item/akka-tshirt
  • Checkout the cart
curl -i -XPOST localhost:9000/carts/123/checkout

Explore the local console

To get a clear view of your locally running service, install the Akka CLI. It provides a local web-based management console.

After you have installed the CLI, start the local console:

akka local console

` This will start a Docker container running the local console:

───────────────────────────────────────────────────────────────────────
│ SERVICE                      │ STATE    │ ADDRESS                   |
───────────────────────────────────────────────────────────────────────
│ shopping-cart-quickstart     │ Running  │ localhost:9000            │
───────────────────────────────────────────────────────────────────────
Local console: http://localhost:9889
(use Ctrl+C to quit)

You can open http://localhost:9889/ to see your local service in action.

Deploy to akka.io

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 name and tag from above mvn install:

akka service deploy shopping-cart shopping-cart-quickstart:tag-name --push

Refer to Deploy and manage services for more information.

Next steps

Now that you've built and deployed a shopping cart service, take your Akka skills to the next level:

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

About

Sample used for Akka documentation's shopping cart starter

Resources

Stars

3 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages