Use Catalyst Quickstart with Azure
In this tutorial, you will select one of the API quickstart applications to try out the Catalyst APIs using Azure resources. The source code used for this tutorial can be found in the catalyst-quickstarts GitHub repository.
Select the API quickstart you would like to deploy to Azure:
- Pub/Sub
- State
- Invocation
Prerequisites
Requirement | Instructions |
---|---|
Diagrid Account | To sign up for Catalyst, visit catalyst.diagrid.io |
Diagrid CLI | Install the Diagrid CLI |
GitHub Account | Get one for free |
Azure Account | If you don't have one, create an account for free |
Azure CLI | Install the Azure CLI |
Log in to Azure
Sign in to Azure.
az login
Ensure you're running the latest version of the Azure CLI via the upgrade command.
az upgrade
Set environment variables
Set environment variables which will be used in the deployment of Azure resources:
export RANDOM_VALUE="$(openssl rand -hex 3)"
export RESOURCE_GROUP="catalyst-rg"
export LOCATION="eastus"
export SERVICEBUS_NAMESPACE="catalyst-ns-$RANDOM_VALUE"
export STORAGEACCOUNT_NAME="orderstatestore$RANDOM_VALUE"
$RANDOM_VALUE ensures the Azure resource names are unique.
Deploy infrastructure services to Azure
Select the API quickstart you plan to deploy to view the relevant instructions.
- Pub/Sub
- State
- Invocation
This tutorial will use Azure Service Bus for the Pub/Sub component target.
Deploy Resource Group
First, create an Azure Resource group to host the resources created as part of the tutorial:
az group create --name $RESOURCE_GROUP --location $LOCATION
Deploy Azure Service Bus
Create an Azure Service Bus Namespace.
az servicebus namespace create --resource-group $RESOURCE_GROUP --name $SERVICEBUS_NAMESPACE --location $LOCATION --sku Standard
Create a topic in the Service Bus Namespace which will provide a one-to-many form of communication via the publish and subscribe pattern.
az servicebus topic create --name orders --namespace-name $SERVICEBUS_NAMESPACE --resource-group $RESOURCE_GROUP
Retrieve the Service Bus connection string and store in an environment variable. This credential will be used by the Diagrid Pub/Sub API to connect to the topic created above.
export SB_CONNECTION_STRING=`az servicebus namespace authorization-rule keys list --resource-group $RESOURCE_GROUP --namespace-name $SERVICEBUS_NAMESPACE --name RootManageSharedAccessKey --query primaryConnectionString -o tsv`
echo $SB_CONNECTION_STRING
This tutorial will use Azure Storage for the State component target. An Azure Storage blob will be created for persisting key/value pairs.
Deploy Resource Group
First, create an Azure Resource group to host the resources created as part of the tutorial:
az group create --name $RESOURCE_GROUP --location $LOCATION
Deploy Azure Storage
Create an Azure Storage Account which will be used by the order-app
app to persist key/value pairs.
az storage account create --name $STORAGEACCOUNT_NAME --resource-group $RESOURCE_GROUP --location $LOCATION --sku Standard_RAGRS --kind StorageV2
Retrieve the Storage Account key and store in an environment variable. This credential will be used by the State API to connect to the storage account created above.
export STORAGE_KEY=`az storage account keys list -g $RESOURCE_GROUP -n $STORAGEACCOUNT_NAME | jq -r '.[0].value'`
echo $STORAGE_KEY
No Azure infrastructure services are needed for service invocation.
Prepare Diagrid Catalyst resources
Log in
Authenticate to your Diagrid Catalyst organization using the following command:
diagrid login
Confirm your login was successful:
diagrid whoami
Create project
If you do not have an existing project available within your organization, create a new Catalyst project.
diagrid project create catalyst-project -w
To ensure this project is set as the default project in the Diagrid CLI, run:
diagrid project use catalyst-project
Retrieve the HTTP and gRPC endpoints for your Catalyst project. These endpoints will be used to make requests to Catalyst from the quickstart application.
export DAPR_HTTP_ENDPOINT=$(diagrid project get -o json | jq -r '.status.endpoints.http.url')
export DAPR_GRPC_ENDPOINT=$(diagrid project get -o json | jq -r '.status.endpoints.grpc.url')
echo $DAPR_HTTP_ENDPOINT && echo $DAPR_GRPC_ENDPOINT
Create App IDs
In Catalyst, each application is represented via a corresponding remote identity, known as an App ID
. An App ID functions as the single point of contact for all interactions between a specific application and the Catalyst APIs.
- Pub/Sub
- State
- Invocation
Create two App IDs: one for the publishing app and one for the subscribing app.
diagrid appid create publisher && diagrid appid create subscriber
Retrieve the API token for the publisher
App ID. App ID API tokens are used to authenticate API requests to Catalyst.
export PUBLISHER_API_TOKEN=$(diagrid appid get publisher -o json | jq -r '.status.apiToken')
echo $PUBLISHER_API_TOKEN
Create an App ID for the order app which is managing order state via the State API.
diagrid appid create order-app
Retrieve the API token for the order-app
App ID. App ID API tokens are used to authenticate API requests to Catalyst.
export ORDERAPP_API_TOKEN=$(diagrid appid get order-app -o json | jq -r '.status.apiToken')
echo $ORDERAPP_API_TOKEN
Create two App IDs: one for the client (invoker) app and one for the server (invokee) app.
diagrid appid create client && diagrid appid create server
Retrieve the API token for the client
App ID. App ID API tokens are used to authenticate API requests to Catalyst.
export CLIENT_API_TOKEN=$(diagrid appid get client -o json | jq -r '.status.apiToken')
echo $CLIENT_API_TOKEN
Onboard Azure infrastructure to Catalyst
- Pub/Sub
- State
- Invocation
In order to use Azure Service Bus with the Pub/Sub API, you will to represent that resource in Catalyst via a Pub/Sub Component. The component contains the authentication information needed by Catalyst to securely access the Azure resource.
Create pub/sub component
There are several ways to create components as described in Connect to external infrastructure. In this tutorial, we will use the non-prompt based CLI experience.
Create the Azure Service Bus Pub/Sub Component:
diagrid component create az-pubsub --type pubsub.azure.servicebus.topics --metadata connectionString=$SB_CONNECTION_STRING --scopes publisher,subscriber
diagrid component get az-pubsub
Create topic subscription
To configure the subscriber app to receive messages published by the publisher app through the Pub/Sub API, create a topic subscription targeting the az-pubsub
component with the following details:
- Subscription name:
az-subscription
- Target Pub/Sub component:
az-pubsub
- Topic on which to listen for messages:
orders
- Default route on the subscriber app for message delivery:
/neworder
- Subscribing App IDs (scopes):
subscriber
diagrid subscription create az-subscription --component az-pubsub --topic orders --route /neworder --scopes subscriber
diagrid subscription get az-subscription
In order to use Azure Storage with the State API, you need to represent that resource in Catalyst via a State Component. The component contains the authentication information needed by Catalyst to securely access the Azure resource.
Create state component
There are several ways to create components as described in Connect to external infrastructure. In this tutorial, we will use the non-prompt based CLI experience.
Create the Azure Storage State Component:
diagrid component create az-statestore --type state.azure.blobstorage --metadata accountName=$STORAGEACCOUNT_NAME --metadata accountKey=$STORAGE_KEY --metadata containerName="orders" --scopes order-app
diagrid component get az-statestore
No components need to be onboarded for service invocation.
Deploy containerized quickstart applications to Azure
This tutorial uses the quickstart apps available in the catalyst-quickstarts GitHub repository. These applications have been containerized and pushed to a public registry.
- Pub/Sub
- State
- Invocation
For the Pub/Sub quickstart, you will deploy two services:
publisher
app which makes requests to the Catalyst Publish APIsubscriber
app which subscribes to and receives the messages published by thepublisher
app through Catalyst
To make API requests to Catalyst, the publisher application uses the OSS Dapr SDKs. Environment variables will be configured to enable the Dapr Client to connect to Catalyst instead of a locally-running Dapr sidecar.
Learn more about using the Dapr SDKs to access Catalyst APIs here.
Run the below command to specify a language for the quickstart:
- Python
- .NET
- JavaScript
- Java
export LANGUAGE=python
export LANGUAGE=csharp
export LANGUAGE=javascript
export LANGUAGE=java
Deploy publisher application
Select the hosting platform where you want the publisher application to run.
- Container Apps
Ensure you have the necessary extensions installed and providers registered for working with Azure Container Apps (ACA).
az extension add --name containerapp --upgrade --allow-preview true
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Deploy the publisher application to ACA. This command will:
- Deploy the sample application in the language of your choice to an ACA environment
- Configure the environment variables required for the application to make Catalyst API calls
- Expose the container app on a publically-accessible endpoint
az containerapp up \
--name publisher \
--resource-group $RESOURCE_GROUP \
--ingress external --target-port 5001 \
--image 'public.ecr.aws/diagrid/pubsub-'${LANGUAGE}'-publisher-qs:latest' \
--env-vars DAPR_HTTP_ENDPOINT="$DAPR_HTTP_ENDPOINT" DAPR_GRPC_ENDPOINT="$DAPR_GRPC_ENDPOINT" DAPR_API_TOKEN="$PUBLISHER_API_TOKEN" PUBSUB_NAME="az-pubsub"
Retrieve the application FQDN for the publisher application.
export PUBLISHER_APP_ENDPOINT=https://`az containerapp show --name publisher --resource-group $RESOURCE_GROUP | jq -r .properties.configuration.ingress.fqdn`
echo $PUBLISHER_APP_ENDPOINT
Deploy subscriber application
Select the hosting platform where you want the subscriber application to run.
- Container Apps
Ensure you have the necessary extensions installed and providers registered for working with Azure Container Apps (ACA).
az extension add --name containerapp --upgrade --allow-preview true
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Deploy the subscriber application to ACA. This command will:
- Deploy the sample application in the language of your choice to an ACA environment
- Expose the container app on a publically-accessible endpoint
az containerapp up \
--name subscriber \
--resource-group $RESOURCE_GROUP \
--ingress external --target-port 5002 \
--image 'public.ecr.aws/diagrid/pubsub-'${LANGUAGE}'-subscriber-qs:latest' \
--env-vars PUBSUB_NAME="az-pubsub"
Retrieve the application FQDN for the subscriber application.
export SUBSCRIBER_APP_ENDPOINT=https://`az containerapp show --name subscriber --resource-group $RESOURCE_GROUP | jq -r .properties.configuration.ingress.fqdn`
echo $SUBSCRIBER_APP_ENDPOINT
Update the subscriber App ID with an app endpoint
To ensure incoming App ID requests and events can be forwarded to the subscriber application, update the subscriber
App ID with the subscriber application endpoint and wait for the operation to complete.
diagrid appid update subscriber --app-endpoint $SUBSCRIBER_APP_ENDPOINT -w
For the State quickstart you will deploy one service:
order-app
which makes requests to the Catalyst State API
To make API requests to Catalyst, the order-app application uses the OSS Dapr SDKs. Environment variables will be configured to enable the Dapr Client to connect to Catalyst instead of a locally-running Dapr sidecar.
Learn more about using the Dapr SDKs to access Catalyst APIs here.
Run the below command to specify a language for the quickstart:
- Python
- .NET
- JavaScript
- Java
export LANGUAGE=python
export LANGUAGE=csharp
export LANGUAGE=javascript
export LANGUAGE=java
Deploy order-app application
- Container Apps
Ensure you have the necessary extensions installed and providers registered for working with Azure Container Apps (ACA).
az extension add --name containerapp --upgrade --allow-preview true
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Deploy the order-app application to ACA. This command will:
- Deploy the sample application in the language of your choice to an ACA environment
- Configure the environment variables required for the application to make Catalyst API calls
- Expose the container app on a publically-accessible endpoint
az containerapp up \
--name order-app \
--resource-group $RESOURCE_GROUP \
--ingress external --target-port 5001 \
--image 'public.ecr.aws/diagrid/state-'${LANGUAGE}'-qs:latest' \
--env-vars DAPR_HTTP_ENDPOINT="$DAPR_HTTP_ENDPOINT" DAPR_GRPC_ENDPOINT="$DAPR_GRPC_ENDPOINT" DAPR_API_TOKEN="$ORDERAPP_API_TOKEN" STATESTORE_NAME="az-statestore"
Retrieve the application FQDN for the order-app application.
export ORDERAPP_APP_ENDPOINT=https://`az containerapp show --name order-app --resource-group $RESOURCE_GROUP | jq -r .properties.configuration.ingress.fqdn`
echo $ORDERAPP_APP_ENDPOINT
For the Service Invocation quickstart, you will deploy two services:
client
app which makes requests to the Catalyst Invoke APIserver
app which receives the invocation request made by theclient
app through Catalyst
To make API requests to Catalyst, the client application uses the OSS Dapr SDKs. Environment variables will be configured to enable the Dapr Client to connect to Catalyst instead of a locally-running Dapr sidecar.
Learn more about using the Dapr SDKs to access Catalyst APIs here.
Run the below command to specify a language for the quickstart:
- Python
- .NET
- JavaScript
- Java
export LANGUAGE=python
export LANGUAGE=csharp
export LANGUAGE=javascript
export LANGUAGE=java
Deploy client application
Select the hosting platform where you want the client application to run.
- Container Apps
Ensure you have the necessary extensions installed and providers registered for working with Azure Container Apps (ACA).
az extension add --name containerapp --upgrade --allow-preview true
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Deploy the client application to ACA. This command will:
- Deploy the sample application in the language of your choice to an ACA environment
- Configure the environment variables required for the application to make Catalyst API calls
- Expose the container app on a publically-accessible endpoint
az containerapp up \
--name client \
--resource-group $RESOURCE_GROUP \
--ingress external --target-port 5001 \
--image 'public.ecr.aws/diagrid/invoke-'${LANGUAGE}'-client-qs:latest' \
--env-vars DAPR_HTTP_ENDPOINT="$DAPR_HTTP_ENDPOINT" DAPR_GRPC_ENDPOINT="$DAPR_GRPC_ENDPOINT" DAPR_API_TOKEN="$CLIENT_API_TOKEN" INVOKE_APPID="server"
Retrieve the application FQDN for the publisher application.
export CLIENT_APP_ENDPOINT=https://`az containerapp show --name client --resource-group $RESOURCE_GROUP | jq -r .properties.configuration.ingress.fqdn`
echo $CLIENT_APP_ENDPOINT
Deploy server application
Select the hosting platform where you want the server application to run.
- Container Apps
Ensure you have the necessary extensions installed and providers registered for working with Azure Container Apps (ACA).
az extension add --name containerapp --upgrade --allow-preview true
az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Deploy the server application to ACA. This command will:
- Deploy the sample application in the language of your choice to an ACA environment
- Expose the container app on a publically-accessible endpoint
az containerapp up \
--name server \
--resource-group $RESOURCE_GROUP \
--ingress external --target-port 5002 \
--image 'public.ecr.aws/diagrid/invoke-'${LANGUAGE}'-server-qs:latest' \
Retrieve the application FQDN for the subscriber application.
export SERVER_APP_ENDPOINT=https://`az containerapp show --name server --resource-group $RESOURCE_GROUP | jq -r .properties.configuration.ingress.fqdn`
echo $SERVER_APP_ENDPOINT
Update the server App ID with an app endpoint
To ensure incoming App ID requests and events can be forwarded to the server application, update the server
App ID with the server application endpoint and wait for the operation to complete.
diagrid appid update server --app-endpoint $SERVER_APP_ENDPOINT -w
Interact with the Catalyst APIs
- Pub/Sub
- State
- Invocation
Use this command to kick off API calls from the publisher application which in turn uses the Catalyst Publish API.
curl -i -X POST $PUBLISHER_APP_ENDPOINT/order -H "Content-Type: application/json" -d '{"orderId":1}'
Check API Logs
Navigate to the Catalyst console to confirm the request was successful using the API Logs. You should see two requests:
- An inbound request from the publisher app using the publisher App ID API token to publish the order message
- An outbound request from the subscriber App ID to deliver the message to the configured Azure app endpoint
Use these commands to kick off API calls from the order-app application which in turn calls the Catalyst State API:
Save a key/value pair
curl -i -X POST $ORDERAPP_APP_ENDPOINT/order -H "Content-Type: application/json" -d '{"orderId":1}'
Update the value of orderId in the data payload with a new key to store another key/value pair.
Retrieve an existing key/value pair
curl -i -X GET $ORDERAPP_APP_ENDPOINT/order/1
Delete an existing key/value pair
curl -i -X DELETE $ORDERAPP_APP_ENDPOINT/order/1
Use this command to kick off API calls from the client application which in turn uses the Catalyst Invocation API.
curl -i -X POST https://$CLIENT_APP_ENDPOINT/order -H "Content-Type: application/json" -d '{"orderId":1}'
Clean up resources
You can use these commands to clean up the Azure and Catalyst resources you created once you are done using them.
- Pub/Sub
- State
- Invocation
Delete Azure Resources
az group delete --name $RESOURCE_GROUP
Delete Catalyst resources
diagrid appid delete publisher
diagrid appid delete subscriber
diagrid component delete az-pubsub
If you want to delete the entire Catalyst project, including the managed infrastructure resources, run the diagrid project delete
command.
diagrid project delete catalyst-project
Delete Azure Resources
az group delete --name $RESOURCE_GROUP
Delete Catalyst resources
diagrid appid delete order-app
diagrid component delete az-statestore
If you want to delete the entire Catalyst project, including the managed infrastructure resources, run the diagrid project delete
command.
diagrid project delete catalyst-project
Delete Azure Resources
az group delete --name $RESOURCE_GROUP
Delete Catalyst resources
diagrid appid delete client
diagrid appid delete server
If you want to delete the entire Catalyst project, including the managed infrastructure resources, run the diagrid project delete
command.
diagrid project delete catalyst-project