Deploying service invocation to Azure Container Apps
Table of contents
In this assignment, you will deploy the service communication to Azure Container Apps (ACA). You will use the service invocation building block provided by Dapr.
Pre-requisites
- The first part Invoke Vehicle Registration Service from Fine Collection Service using Dapr is a pre-requisite for this assignment.
- Assignment 5 - Deploying to Azure Container Apps is also a pre-requisite for this assignment.
Step 1: Enable Dapr for Vehicle Registration Service
In this step, you will enable Dapr for the VehicleRegistrationService
to be discoverable by the FineCollectionService
using Dapr’s service invocation building block.
FineCollectionService
Dapr sidecar uses Vehicle Registration Service dapr-app-id
to resolve the service invocation endpoint. The name (i.e. dapr-app-id
) of VehicleRegistrationService
is set in the application properties of FineCollectionService
(i.e. application.yaml
) as shown below:
vehicle-registration-service.name: ${VEHICLE_REGISTRATION_SERVICE:vehicleregistrationservice}
The default value is vehicleregistrationservice
that will be override using the environment variable VEHICLE_REGISTRATION_SERVICE
to the name set in the following step:
-
Open a new termninale and run the following command to enable Dapr for
VehicleRegistrationService
:az containerapp dapr enable \ --name ca-vehicle-registration-service \ --resource-group rg-dapr-workshop-java \ --dapr-app-id vehicle-registration-service \ --dapr-app-port 6002 \ --dapr-app-protocol http
-
Note the
dapr-app-id
you set in the previous step. It is used to resolve the service invocation endpoint.
Step 2: Build and redeploy fine collection service
In this step, you will rebuild and redeploy the FineCollectionService
to use the VehicleRegistrationService
service invocation endpoint.
-
Delete the image from local docker:
docker rmi fine-collection-service:1.0-SNAPSHOT
-
In the root folder of
FineCollectionService
, run the following command to build and push the image:mvn spring-boot:build-image docker tag fine-collection-service:1.0-SNAPSHOT "$CONTAINER_REGISTRY.azurecr.io/fine-collection-service:2.0" docker push "$CONTAINER_REGISTRY.azurecr.io/fine-collection-service:2.0"
Where
$CONTAINER_REGISTRY
is the name of your Azure Container Registry. -
Update
FineCollectionService
container app with the new image and with the environment variable to set the name (i.e.dapr-app-id
) ofVehicleRegistrationService
:az containerapp update \ --name ca-fine-collection-service \ --resource-group rg-dapr-workshop-java \ --image "$CONTAINER_REGISTRY.azurecr.io/fine-collection-service:2.0" \ --set-env-vars "VEHICLE_REGISTRATION_SERVICE=vehicle-registration-service" \ --remove-env-vars "VEHICLE_REGISTRATION_SERVICE_BASE_URL"
Where
$CONTAINER_REGISTRY
is the name of your Azure Container Registry. TheVEHICLE_REGISTRATION_SERVICE_BASE_URL
is removed because it is not used anymore.
Step 3 - Run the simulation
-
Set the following environment variable:
-
Linux/Unix shell:
export TRAFFIC_CONTROL_SERVICE_BASE_URL=https://$TRAFFIC_CONTROL_SERVICE_FQDN
-
Powershell:
$env:TRAFFIC_CONTROL_SERVICE_BASE_URL = "https://$TRAFFIC_CONTROL_SERVICE_FQDN"
-
-
In the root folder of the simulation (
Simulation
), start the simulation:mvn spring-boot:run
Step 4 - Test the microservices running in ACA
You can access the log of the container apps from the Azure Portal or directly in a terminal window. To access the logs in the portal, you need to go to your resource group rg-dapr-workshop-java
and select the container app for which you need the log. Then select Log stream
in Monitoring
section.
To access the logs from the terminal, follow the instructions below for each microservice.
The logs can take a few minutes to appear in the Log Analytics Workspace. If the logs are not updated, open the log stream in the Azure Portal.
Traffic Control Service
-
Run the following command to identify the running revision of traffic control service container apps:
-
Linux/Unix shell:
TRAFFIC_CONTROL_SERVICE_REVISION=$(az containerapp revision list -n ca-traffic-control-service -g rg-dapr-workshop-java --query "[0].name" -o tsv) echo $TRAFFIC_CONTROL_SERVICE_REVISION
-
Powershell:
$TRAFFIC_CONTROL_SERVICE_REVISION = az containerapp revision list -n ca-traffic-control-service -g rg-dapr-workshop-java --query "[0].name" -o tsv $TRAFFIC_CONTROL_SERVICE_REVISION
-
-
Run the following command to get the last 10 lines of traffic control service logs from Log Analytics Workspace:
az monitor log-analytics query \ --workspace $LOG_ANALYTICS_WORKSPACE_CUSTOMER_ID \ --analytics-query "ContainerAppConsoleLogs_CL | where RevisionName_s == '$TRAFFIC_CONTROL_SERVICE_REVISION' | project TimeGenerated, Log_s | sort by TimeGenerated desc | take 10" \ --out table
Fine Collection Service
-
Run the following command to identify the running revision of fine collection service container apps:
-
Linux/Unix shell:
FINE_COLLECTION_SERVICE_REVISION=$(az containerapp revision list -n ca-fine-collection-service -g rg-dapr-workshop-java --query "[0].name" -o tsv) echo $FINE_COLLECTION_SERVICE_REVISION
-
Powershell:
$FINE_COLLECTION_SERVICE_REVISION = az containerapp revision list -n ca-fine-collection-service -g rg-dapr-workshop-java --query "[0].name" -o tsv $FINE_COLLECTION_SERVICE_REVISION
-
-
Run the following command to get the last 10 lines of fine collection service logs from Log Analytics Workspace:
az monitor log-analytics query \ --workspace $LOG_ANALYTICS_WORKSPACE_CUSTOMER_ID \ --analytics-query "ContainerAppConsoleLogs_CL | where RevisionName_s == '$FINE_COLLECTION_SERVICE_REVISION' | project TimeGenerated, Log_s | sort by TimeGenerated desc | take 10" \ --out table
Vehicle Registration Service
-
Run the following command to identify the running revision of vehicle registration service container apps:
-
Linux/Unix shell:
VEHICLE_REGISTRATION_SERVICE_REVISION=$(az containerapp revision list -n ca-vehicle-registration-service -g rg-dapr-workshop-java --query "[0].name" -o tsv) echo $VEHICLE_REGISTRATION_SERVICE_REVISION
-
Powershell:
$VEHICLE_REGISTRATION_SERVICE_REVISION = az containerapp revision list -n ca-vehicle-registration-service -g rg-dapr-workshop-java --query "[0].name" -o tsv $VEHICLE_REGISTRATION_SERVICE_REVISION
-
-
Run the following command to get the last 10 lines of vehicle registration service logs from Log Analytics Workspace:
az monitor log-analytics query \ --workspace $LOG_ANALYTICS_WORKSPACE_CUSTOMER_ID \ --analytics-query "ContainerAppConsoleLogs_CL | where RevisionName_s == '$VEHICLE_REGISTRATION_SERVICE_REVISION' | project TimeGenerated, Log_s | sort by TimeGenerated desc | take 10" \ --out table
Check Application Map of Application Insights in Azure Portal to see the connection between the FineCollectionService
and the VehicleRegistrationService
.
Cleanup
When the workshop is done, please follow the cleanup instructions to delete the resources created in this workshop.