Quickstart: Deploy an event-driven application to Azure Spring Apps
Article
Note
The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.
The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps.
This article explains how to deploy a Spring Boot event-driven application to Azure Spring Apps.
The sample project is an event-driven application that subscribes to a Service Bus queue named lower-case, and then handles the message and sends another message to another queue named upper-case. To make the app simple, message processing just converts the message to uppercase. The following diagram depicts this process:
This article provides the following options for deploying to Azure Spring Apps:
The Azure portal option is the easiest and the fastest way to create resources and deploy applications with a single click. This option is suitable for Spring developers who want to quickly deploy applications to Azure cloud services.
The Azure portal + Maven plugin option is a more conventional way to create resources and deploy applications step by step. This option is suitable for Spring developers using Azure cloud services for the first time.
The Azure Developer CLI option is a more efficient way to automatically create resources and deploy applications through simple commands. The Azure Developer CLI uses a template to provision the Azure resources needed and to deploy the application code. This option is suitable for Spring developers who are familiar with Azure cloud services.
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:
The sample project is ready on GitHub. Clone the sample project by using the following command:
Build the sample project by using the following commands:
cd ASA-Samples-Event-Driven-Application
./mvnw clean package
Use the following steps to prepare the sample locally. These steps use AZD to initialize the event-driven application from the Azure Developer CLI templates.
Open a terminal, create a new, empty folder, then navigate to it.
Use the following command to initialize the project:
The following list describes the command interactions:
Enter a new environment name: Provide an environment name, which is used as a suffix for the resource group that is created to hold all Azure resources. This name should be unique within your Azure subscription.
The console outputs messages similar to the following example:
Initializing a new project (azd init)
(✓) Done: Initialized git repository
(✓) Done: Downloading template code to: <your-local-path>
Enter a new environment name: <your-env-name>
SUCCESS: New project initialized!
You can view the template code in your directory: <your-local-path>
Learn more about running 3rd party code on our DevHub: https://aka.ms/azd-third-party-code-notice
3. Prepare the cloud environment
The main resources you need to run this sample are an Azure Spring Apps instance, an Azure Key Vault instance, and an Azure Service Bus instance. Use the following steps to create these resources.
This section uses a Deploy to Azure button to launch a deployment experience in the Azure portal. This experience uses an ARM template to create Azure resources.
3.1. Sign in to the Azure portal
Go to the Azure portal and enter your credentials to sign in to the portal. The default view is your service dashboard.
3.2. Create Azure resources
Use the following steps to create all the Azure resources that the app depends on:
Select the following Deploy to Azure button to launch the deployment experience in the Azure portal:
Fill out the form on the Basics tab. Use the following table as a guide for completing the form:
Setting
Suggested value
Description
Subscription
Your subscription name.
The Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you'd like to be billed for the resource.
Resource group
myresourcegroup
A new resource group name or an existing one from your subscription.
Region
The region closest to your users.
The region is used to create the resource group.
Select Review and Create to review your selections. Then, select Create to deploy the app to Azure Spring Apps.
On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. After the deployment finishes, you can select Pin to dashboard, which creates a tile for this service on your Azure portal dashboard as a shortcut to the service's Overview page. Select Go to resource to open the service's Overview page.
3.1. Sign in to the Azure portal
Open your web browser and go to the Azure portal. Enter your credentials to sign in to the portal. The default view is your service dashboard.
3.2. Create a Service Bus instance
Use the following steps to create a Service Bus instance:
Select Create a resource in the corner of the Azure portal.
In the Search services and marketplace search box, search for service bus.
On the Service Bus section, select Create.
Fill out the form on the Basics tab. Use the following table as a guide for completing the form:
Setting
Suggested value
Description
Subscription
Your subscription name.
The Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you'd like to be billed for the resource.
Resource group
myresourcegroup
A new resource group name or an existing one from your subscription.
Namespace name
my-srvbus
A unique name that identifies your Service Bus service.
Location
The location closest to your users.
The location that is closest to your users.
Hosting options and plans
Basic
The pricing plan determines the resource and cost associated with your instance.
Select Review and Create to review the creation parameters. Then, select Create to finish creating the Service Bus instance.
On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. After the deployment finishes, you can select Pin to dashboard, which creates a tile for this service on your Azure portal dashboard as a shortcut to the service's Overview page. Select Go to resource to open the service's Overview page.
Select Go to resource to go to the Service Bus Namespace page.
Select Shared access policies on the navigation menu and then select RootManageSharedAccessKey.
On the SAS Policy: RootManageSharedAccessKey page, copy and save the Primary Connection String value, which is used to set up connections from the Spring app.
Select Queues on the navigation menu and 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.
3.3. Create an Azure Spring Apps instance
Use the following steps to create an Azure Spring Apps instance:
Select Create a resource in the corner of the Azure portal.
Select Compute > Azure Spring Apps.
Fill out the Basics form with the following information:
Use the following table as a guide for completing the form. The recommended Plan is Standard.
Setting
Suggested value
Description
Subscription
Your subscription name
The Azure subscription that you want to use for your server. If you have multiple subscriptions, choose the subscription in which you'd like to be billed for the resource.
Resource group
myresourcegroup
A new resource group name or an existing one from your subscription.
Name
myasa
A unique name that identifies your Azure Spring Apps service. The name must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number.
Plan
Standard
The plan determines the resource and cost associated with your instance.
Region
The region closest to your users
The location that is closest to your users.
Zone Redundant
Unselected
Whether to create your Azure Spring Apps service in an Azure availability zone, it could only be supported in several regions at the moment.
Select Review and Create to review your selections. Select Create to provision the Azure Spring Apps instance.
On the toolbar, select the Notifications icon (a bell) to monitor the deployment process. Once the deployment is done, you can select Pin to dashboard, which creates a tile for this service on your Azure portal dashboard as a shortcut to the service's Overview page. Selecting Go to resource opens the service's Overview page.
3.4. Connect app instance to Service Bus instance
Go to your Azure Spring Apps instance in the Azure portal.
Select Apps in the navigation menu, then select Create App.
On the Create App page, enter simple-event-driven-app for App name and select Java 17 for Runtime platform.
After the app creation, select the app name you created in the previous step.
On the Configuration page, select the Environment variables tab, enter SERVICE_BUS_CONNECTION_STRING for Key, paste the Service Bus connection string for Value, then select Save.
Use the following command to sign in to Azure with OAuth2. Ignore this step if you already logged in.
azd auth login
The console outputs messages similar to the following example:
Logged in to Azure.
Use the following command to set the template using the standard plan:
azd env set PLAN standard
Use the following command to package a deployable copy of your application, provision the template's infrastructure to Azure, and deploy the application code to those newly provisioned resources:
azd provision
The following list describes the command interactions:
Select an Azure Subscription to use: Use arrows to move, type to filter, then press Enter.
Select an Azure location to use: Use arrows to move, type to filter, then press Enter.
The console outputs messages similar to the following example:
SUCCESS: Your application was provisioned in Azure in xx minutes xx seconds.
You can view the resources created under the resource group rg-<your-environment-name> in Azure Portal:
https://portal.azure.cn/#@/resource/subscriptions/<your-subscription-id>/resourceGroups/rg-<your-environment-name>/overview
Note
This command may take a while to complete. You're shown a progress indicator as it provisions Azure resources.
The Deploy to Azure button in the previous section launches an Azure portal experience that includes application deployment, so nothing else is needed.
The following list describes the command interactions:
OAuth2 login: You need to authorize the sign in to Azure based on the OAuth2 protocol.
Select subscription: Select the subscription list number of the Azure Spring Apps instance you created, which defaults to the first subscription in the list. If you use the default number, press Enter directly.
Use existing Azure Spring Apps in Azure: Press y to use the existing Azure Spring Apps instance.
Select Azure Spring Apps for deployment: Select the list number of the Azure Spring Apps instance you created. If you use the default number, press Enter directly.
Use existing app in Azure Spring Apps <your-instance-name>: Press y to use the app created.
Confirm to save all the above configurations: Press y. If you press n, the configuration isn't saved in the POM files.
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] Deployment(default) is successfully created
[INFO] Starting Spring App after deploying artifacts...
[INFO] Deployment Status: Running
Use the following steps to use AZD to package the app, provision the Azure resources required by the web application, and then deploy to Azure Spring Apps.
Use the following command to package a deployable copy of your application:
azd package
The console outputs messages similar to the following example:
SUCCESS: Your application was packaged for Azure in xx seconds.
Use the following command to deploy the application code to those newly provisioned resources:
azd deploy
The console outputs messages similar to the following example:
Deploying services (azd deploy)
(✓) Done: Deploying service simple-event-driven-app
- No endpoints were found
SUCCESS: Your application was deployed to Azure in xx minutes xx seconds.
You can view the resources created under the resource group rg-<your-environment-name> in Azure Portal:
https://portal.azure.cn/#@/resource/subscriptions/<your-subscription-id>/resourceGroups/rg-<your-environment-name>/overview
Note
You can also use azd up to combine the previous three commands: azd provision (provisions Azure resources), azd package (packages a deployable copy of your application), and azd deploy (deploys application code). For more information, see Azure-Samples/ASA-Samples-Event-Driven-Application.
5. Validate the app
Use the following steps to confirm that the event-driven app works correctly. You can validate the app by sending a message to the lower-case queue, then confirm that there's a message in the upper-case queue.
Go to the Azure Spring Apps instance Overview page and select Logs to check the app's logs.
6. Clean up resources
Be sure to delete the resources you created in this article when you no longer need them. You can delete the Azure resource group, which includes all the resources in the resource group.