Running the sample code

  1. Start a local PostgreSQL server on default port 5432. The included docker-compose.yml starts everything required for running locally.

    docker compose up --wait
    
    # creates the tables needed for Akka Persistence
    # as well as the offset store table for Akka Projection
    docker exec -i postgres-db psql -U shopping-cart -t < ddl-scripts/create_tables.sql
  2. Start a first node:

    sbt -Dconfig.resource=local1.conf run
  3. (Optional) Start another node with different ports:

    sbt -Dconfig.resource=local2.conf run
  4. (Optional) More can be started:

    sbt -Dconfig.resource=local3.conf run
  5. Check for service readiness

    curl http://localhost:9101/ready
  6. Try it with grpcurl. Add at least a total quantity of 10 to the cart, smaller carts are excluded by the event filter.

    # add item to cart
    grpcurl -d '{"cartId":"cart1", "itemId":"socks", "quantity":3}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.AddItem
    
    # get cart
    grpcurl -d '{"cartId":"cart1"}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.GetCart
    
    # update quantity of item
    grpcurl -d '{"cartId":"cart1", "itemId":"socks", "quantity":5}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.AddItem
    
    # check out cart
    grpcurl -d '{"cartId":"cart1"}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.Checkout
    

    or same grpcurl commands to port 8102 to reach node 2.