The main steps required to deploy a stateful application include:
Deploying required services
To do this, Akka Serverless needs access to the container image registry hosting the packaged services. For this example, we give you access to a pre-built and packaged version of the example that is published in Lightbend’s registry.
Exposing the services for external access
In the case of the Shopping Cart example, this provides HTTP access to the frontend and shopping cart services.
Watch this video to get a preview of the example app:
Deploy the packaged Shopping Cart application by following these steps:
In a command or terminal window, if you haven’t authorized
akkasls, enter the following command:
akkasls auth login
If you are not logged in, log in.
akkaslsprompt should return, confirming you are now authorized.
akkasls projects new shopping-cart-js "Shopping Cart Sample(JS)"
The project will not be active until you receive an email approving it.
After you receive the approval email, list your projects:
akkasls projects list
The output should look similar to the following, of course with a different ID:
NAME DESCRIPTION STATUS ID shopping-cart-js Shopping Cart Sample(JS) active 54b7757f-4f22-494f-9ffc-5bbfcec28088
Set your project to be the current Akka Serverless project:
akkasls config set project shopping-cart-js
Now subsequent commands will apply to the Shopping Cart project.
Copy and paste the following to deploy the
akkasls svc deploy \ shopping-cart \ lightbend-docker-registry.bintray.io/cloudstate-samples/shopping-cart-js
Verify the status of the
akkasls svc list
shopping-cartservice status is
Ready, expose the shopping-cart service with CORS header support:
akkasls svc expose shopping-cart --enable-cors
A message similar to the following displays:
Service 'shopping-cart' was successfully exposed at: snowy-truth-4046.us-east1.apps.cloudstate.com
Copy the hostname on which the
Navigate to the statically hosted web UI:
When prompted, enter the hostname you copied earlier.
You should now see the running shopping cart application.
Check if the shopping cart service is stateful in UI
Enter any user name in the UI.
Add items to your cart.
Click the shopping cart to view the items you added.
Close the browser.
Open the browser again with the shopping cart URL.
Enter the same user name, which connects to our stateful service.
Click the shopping cart.
All of the items you added before closing the browser should still be there, showing that the service is stateful!
To learn how to create this example, see Tutorial: Create a shopping cart with Node.js.