author | ms.author | ms.service | ms.custom | ms.topic | ms.date |
---|---|---|---|---|---|
karlerickson | v-shilichen | azure-spring-apps | devx-track-azurecli | include | 07/19/2023 |
The Deploy to Azure button in the next section launches an Azure portal experience that downloads a JAR package from the ASA-Samples-Web-Application releases page on GitHub. No local preparation steps are needed.
Use the following steps to prepare the sample locally:
[!INCLUDE prepare-spring-project-git-event-driven]
Use the following steps to prepare the sample locally:
[!INCLUDE prepare-spring-project-git-event-driven]
The main resources you need to run this sample are an Azure Spring Apps instance and an Azure Service Bus instance. The following sections describe how to create these resources.
[!INCLUDE prepare-cloud-environment-on-azure-portal]
Go to the Azure portal and enter your credentials to sign in to the portal. The default view is your service dashboard.
[!INCLUDE provision-service-bus]
Select Queues on the navigation menu, then select Queue.
On the Create Queue page, enter lower-case for Name and then select Create.
Create another queue by repeating the previous step using upper-case for Name.
[!INCLUDE provision-enterprise-azure-spring-apps]
Use the following steps to connect your service instances:
Go to your Azure Spring Apps instance in the Azure portal.
From the navigation pane, open the Apps pane and then select Create App.
On the Create App page, for the app name, use simple-event-driven-app and leave all the other fields with their default values.
Select Create to finish creating the app and then select the app to view the details.
Select Service Connector from the navigation pane and then select Create to create a new service connection.
Fill out the Basics tab with the following information:
- Service type: Select Service Bus.
- Connection name: Populated with an automatically generated name that you can modify.
- Subscription: Select your subscription.
- Namespace: Select the namespace you created.
- Client type: Select SpringBoot.
Configure the Next: Authentication tab with the following information:
[!INCLUDE security-note]
- Select the authentication type you'd like to use between your compute service and target service.: Select Connection string.
Select Next: Networking. Use the default option Configure firewall rules to enable access to target service.
Select Next: Review and Create to review your selections, then select Create to create the connection.
Create variables to hold the resource names by using the following commands. Be sure to replace the placeholders with your own values.
export RESOURCE_GROUP=<event-driven-app-resource-group-name> export LOCATION=<desired-region> export SERVICE_BUS_NAME_SPACE=<event-driven-app-service-bus-namespace> export AZURE_SPRING_APPS_INSTANCE=<Azure-Spring-Apps-instance-name> export APP_NAME=<event-driven-app-name>
Use the following steps to create a new resource group:
Use the following command to sign in to the Azure CLI:
az login
Use the following command to set the default location:
az configure --defaults location=${LOCATION}
Use the following command to list all available subscriptions to determine the subscription ID to use:
az account list --output table
Use the following command to set the default subscription:
az account set --subscription <subscription-ID>
Use the following command to create a resource group:
az group create --resource-group ${RESOURCE_GROUP}
Use the following command to set the newly created resource group as the default resource group:
az configure --defaults group=${RESOURCE_GROUP}
Use the following commands to install the Azure Spring Apps extension for the Azure CLI and register the Microsoft.SaaS
namespace:
az extension add --name spring --upgrade az provider register --namespace Microsoft.SaaS
Use the following command to create your Azure Spring Apps instance:
az spring create \ --name ${AZURE_SPRING_APPS_INSTANCE} \ --sku Enterprise
Then, use the following command to create an app in the Azure Spring Apps instance:
az spring app create \ --service ${AZURE_SPRING_APPS_INSTANCE} \ --name ${APP_NAME}
Use the following steps to create a Service Bus instance:
Use the following command to create a Service Bus namespace:
az servicebus namespace create --name ${SERVICE_BUS_NAME_SPACE}
Use the following commands to create two queues named
lower-case
andupper-case
:az servicebus queue create \ --namespace-name ${SERVICE_BUS_NAME_SPACE} \ --name lower-case az servicebus queue create \ --namespace-name ${SERVICE_BUS_NAME_SPACE} \ --name upper-case
You've now created both the Service Bus and the app in Azure Spring Apps, but the app can't connect to the Service Bus. Use the following steps to enable the app to connect to the Service Bus, and then deploy the app:
Get the Service Bus's connection string by using the following command:
[!INCLUDE security-note]
export SERVICE_BUS_CONNECTION_STRING=$( \ az servicebus namespace authorization-rule keys list \ --namespace-name ${SERVICE_BUS_NAME_SPACE} \ --name RootManageSharedAccessKey \ --query primaryConnectionString \ --output tsv)
Use the following command to provide the connection string to the app through an environment variable:
az spring app update \ --service ${AZURE_SPRING_APPS_INSTANCE} \ --name ${APP_NAME} \ --env SPRING_CLOUD_AZURE_SERVICEBUS_CONNECTIONSTRING=${SERVICE_BUS_CONNECTION_STRING} \ SPRING_CLOUD_AZURE_KEYVAULT_SECRET_PROPERTYSOURCEENABLED=false
The Deploy to Azure button in the previous section launches an Azure portal experience that includes application deployment, so nothing else is needed.
[!INCLUDE event-driven-spring-apps-maven-plugin]
Use the following command to deploy the app:
./mvnw azure-spring-apps:deploy
The following list describes the command interaction:
- OAuth2 login: You need to authorize the sign in to Azure based on the OAuth2 protocol.
After the command is executed, you can see from the following log messages that the deployment was successful:
[INFO] Starting Spring App after deploying artifacts... [INFO] Deployment Status: Running
The cloud environment is now ready. Deploy the app by using the following command:
az spring app deploy \ --service ${AZURE_SPRING_APPS_INSTANCE} \ --name ${APP_NAME} \ --artifact-path target/simple-event-driven-app-0.0.2-SNAPSHOT.jar