This repository provides a code sample in .NET on how to use some Azure Cosmos DB features integrated with Azure Funcions.
It's recommended to create all the resources within the same region.
-
Create a Function App. Choose the Runtime stack accordingly (sample code provided in .NET 6).
-
- Create
marketdata
Event Hub - Create
ems-orderstoexecute
Event Hub - Create
ems-ordersexecuted
Event Hub - Create
ems-executions
Event Hub
- Create
-
Create a database and containers
- Create
trading
database - Create
orders
container: provide/orderId
as the Partition key, selectAutoscale
and provide1000
as Collection Max RU/s. - Create
orderExecutions
container: provide/orderId
as the Partition key, selectAutoscale
and provide1000
as Collection Max RU/s. - Create
marketdata
container: provide/symbol
as the Partition key, selectAutoscale
and provide1000
as Collection Max RU/s. - Create
customerPortfolio
container using the SDK (Create new container with hierarchical partition keys): provide/customerId
and/assetClass
as the Partition keys, selectAutoscale
and provide1000
as Collection Max RU/s.
- Create
-
Configure application settings
- CosmosDBConnection:
<your Cosmos DB connection string>
- ordersHubConnection:
<your Event Hub namespace connection string>
- CosmosDBConnection:
-
Deploy Function application to Azure (Deploy using VS Code).
You can call Function APIs from Azure Portal or your favorite tool.
-
Call CreateOrder function
curl --request POST 'https://<function app name>.azurewebsites.net/api/orders/create?code=<function code>' \ --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 'https://<function app name>.azurewebsites.net/api/orders/{orderId}?code=<function code>'
-
Call GetExecutions function (use the same orderId)
-- Returns Order Executions by orderId curl --request GET 'https://<function app name>.azurewebsites.net/api/orders/execution/{orderId}?code=<function code>'
-
Call GetCustomerPortfolio function (use customerId provided on step 1)
-- Returns Customer Portfolio by customerId curl --request GET 'https://<function app name>.azurewebsites.net/api/customerPortfolio/{customerId}?code=<function code>'
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 😄