A canonical shopping cart sample application, built using Akka.NET. This app shows the following features:
-
Shopping cart: A simple shopping cart application that uses Akka.NET for its cross-platform framework support, and its scalable distributed applications capabilities.
- Inventory management: Edit and/or create product inventory.
- Shop inventory: Explore purchasable products and add them to your cart.
- Cart: View a summary of all the items in your cart, and manage these items; either removing or changing the quantity of each item.
- .NET 6
- ASP.NET Core Blazor
- Akka.NET: Akka.Persistence
- Akka.NET: Akka.Management
- Azure Bicep
- Azure App Service
The app is architected as follows:
- A GitHub account
- The .NET 6 SDK or later
- The Azure CLI
- A .NET integrated development environment (IDE)
- Feel free to use the Visual Studio IDE or the Visual Studio Code
git clone git@github.com:petabridge/azure-app-service-akkadotnet.git akka-on-app-service
cd akka-on-app-service
dotnet run --project src\Akka.ShoppingCart\Akka.ShoppingCart.csproj
Before deploying the app, you need to create an Azure Resource Group (or you could choose to use an existing one). To create a new Azure Resource Group, use one of the following articles:
The app will need to be packaged for deployment. In the Akka.ShoppingCart
project we define a Target
element that runs after the Publish
step. This will zip the publish directory into a cluster.zip file:
<Target Name="ZipPublishOutput" AfterTargets="Publish">
<Delete Files="$(ProjectDir)\..\..\cluster.zip" />
<ZipDirectory SourceDirectory="$(PublishDir)" DestinationFile="$(ProjectDir)\..\..\cluster.zip" />
</Target>
In this tutorial, we will be using Azure CLI and Azure Bicep to create all of the resources needed by the example project and to deploy the packaged cluster.zip file into Azure App Services.
We will use PowerShell, Azure CLI, and the provided .bicep files to automate our Azure resource creation. In PowerShell, navigate to the project directory and deploy the resources using az deployment group create.
Replace <resource-group-name> with the name of the Azure Resource Group you created earlier and replace <unique-application-name> with a unique name to identify your web application.
az deployment group create `
--resource-group <resource-group-name> `
--template-file 'flex/main.bicep' `
--parameters appName=<unique-application-name> `
--debug
Publish the Akka.ShoppingCart project by using the dotnet publish command in PowerShell
dotnet publish --configuration Release .\src\Akka.ShoppingCart\Akka.ShoppingCart.csproj
Deploy the published cluster.zip file to Azure App Services using az webapp deploy. Again, replace <resource-group-name> and <unique-application-name> the same names you used in the earlier step.
az webapp deploy --name <unique-application-name> `
--resource-group <resource-group-name> `
--clean true --restart true `
--type zip --src-path cluster.zip --debug
Azure App Service will take a few minutes to spin up the web application that will contain a single node Akka.NET cluster. To view the deployed web application, you can go to https://<unique-application-name>.azurewebsites.net
.
You can see Akka.Discovery.Azure
in action by scaling out and increasing the minimum number of server instances in your Azure App Service Plan via Azure Portal.
- In the Azure portal, select your web app name (App service), and in the left menu pane, under Settings, select Scale out (App Service plan). The Scale out (App Service plan) pane appears.
- On the Configure tab, select Manual scale and set the Instance count to 5. In the top menu bar, select Save.
Use the Cluster Status link on the left navigation bar of the deployed website to monitor the cluster state changes as new nodes joins the cluster in real time.
The Bicep files used in this example is nearly identical to the one used in the Orleans example. As noted in their documentation, one very important resource
is that of the Virtual Network. The vnet
resource enables the Azure App Service to communicate with the Akka.NET cluster.
To read more about the Bicep files and how they are used in resource provisioning, please read the documentation.
The Akka.ShoppingCart project uses the following 3rd party open-source projects:
- MudBlazor: Blazor Component Library based on Material design.
- Bogus: A simple fake data generator for C#, F#, and VB.NET.
- Blazorators: Source-generated packages for Blazor JavaScript interop.
Derived from: