This repository provides a code sample in .NET on how to use some Azure Cosmos DB features integrated with Azure Funcions running on Azure Kubernetes Services + KEDA.
Setup shell was tested on WSL2 (Ubuntu 22.04.2 LTS)
The setup will provision and configure all the resources required.
-
Sign in with Azure CLI
az login
-
Clone the repo
git clone https://github.com/fonsecamar/cosmos-trading-keda.git cd cosmos-trading-keda/deploy/
-
Run setup.sh with the appropriete parameters. Keep the API's URIs prompted when completed.
Provide a non-existent resource group name. Setup will provision.
```bash
#SAMPLE
#./setup.sh 00000000-0000-0000-0000-000000000000 rg-my-demo SouthCentralUS myrandomsuffix
./setup.sh <subscription id> <resource group> <location> <resources suffix>
```
Setup has some pause stages. Hit enter to continue when prompted.
It takes around 5min to provision and configure resoures.
Resources created:
- 2 resource groups
- Azure Blob Storage (ADLS Gen2)
- Azure Cosmos DB account (1 database with 1000 RUs autoscale shared with 5 collections) with Analytical Store enabled
- Azure Event Hub standard
- Azure Steam Analytics job
- Azure Container Registry basic
- Azure Kubernetes Service (AKS) (1 node pool - 3 nodes Standard_B4ms)
-
Start Azure Stream Analytics job
-
Run markerdata generator
cd ../src/marketdata-generator dotnet run
-
Check Cosmos DB marketdata container (updated every 15 second by Azure Stream Analytics job).
-
Call GetStockPrice function
#Setting variables SUFFIX=<your suffix> LOCATION=<your location> # Returns Stock Price by symbol curl --request GET "http://ingressdemo$SUFFIX.$LOCATION.cloudapp.azure.com/api/stock/MSFT"
-
Call CreateOrder function
# Creates an Order curl --request POST "http://ingressdemo$SUFFIX.$LOCATION.cloudapp.azure.com/api/orders/create" \ --header 'Content-Type: application/json' \ --data-raw '{ "customerId": 99999999, "quantity": 1000, "symbol": "MSFT", "price": 300, "action": "buy" }'
-
Call GetOrder function (use orderId from the previous response)
# Returns Order by orderId curl --request GET "http://ingressdemo$SUFFIX.$LOCATION.cloudapp.azure.com/api/orders/{orderId}"
-
Call GetExecutions function (use the same orderId)
-- Returns Order Executions by orderId curl --request GET "http://ingressdemo$SUFFIX.$LOCATION.cloudapp.azure.com/api/orders/execution/{orderId}"
-
Call GetCustomerPortfolio function (use customerId provided on step 1)
-- Returns Customer Portfolio by customerId curl --request GET "http://ingressdemo$SUFFIX.$LOCATION.cloudapp.azure.com/api/customerPortfolio/{customerId}"
CTRL + C
to stop marketdata generator- Delete the Resource Group to destroy all resources
If you find any errors or have suggestions for changes, please be part of this project!
- Create your branch:
git checkout -b my-new-feature
- Add your changes:
git add .
- Commit your changes:
git commit -m '<message>'
- Push your branch to Github:
git push origin my-new-feature
- Create a new Pull Request 😄