tree: bc82e1ab4154eed7199ce4b7f56434e0b4ec5233
  1. ddl-scripts/
  2. kubernetes/
  3. src/
  4. .gitignore
  5. docker-compose.yml
  6. LICENSE
  7. pom.xml
  8. README.md
docs-source/docs/modules/microservices-tutorial/examples/shopping-cart-service-java/README.md

Running the sample code

  1. Start a local PostgresSQL server on default port 5432 and a Kafka broker on port 9092. The included docker-compose.yml starts everything required for running locally.

    docker-compose up -d
    
    # creates the tables needed for Akka Persistence
    # as well as the offset store table for Akka Projection
    docker exec -i shopping-cart-service_postgres-db_1 psql -U shopping-cart -t < ddl-scripts/create_tables.sql
    
    # creates the user defined projection table.
    docker exec -i shopping-cart-service_postgres-db_1 psql -U shopping-cart -t < ddl-scripts/create_user_tables.sql
    
  2. Make sure you have compiled the project

    mvn compile 
    
  3. Start a first node:

    mvn compile exec:exec -DAPP_CONFIG=local1.conf
    
  4. (Optional) Start another node with different ports:

    mvn compile exec:exec -DAPP_CONFIG=local2.conf
    
  5. (Optional) More can be started:

    mvn compile exec:exec -DAPP_CONFIG=local3.conf
    
  6. Check for service readiness

    curl http://localhost:9101/ready
    
  7. Try it with grpcurl:

    # 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.UpdateItem
    
    # check out cart
    grpcurl -d '{"cartId":"cart1"}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.Checkout
    
    # get item popularity
    grpcurl -d '{"itemId":"socks"}' -plaintext 127.0.0.1:8101 shoppingcart.ShoppingCartService.GetItemPopularity
    

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