🔥 Make sure you star the repo to keep up to date with new tips and tricks.
💡 Learn more : Azure Spring Cloud.
📺 Watch the video : Working with Azure Spring Cloud.
Azure Spring Cloud makes it easy for you to deploy and run Spring Boot-based microservice applications to Azure. By running your microservices on Azure you get the advantages of the Azure cloud, like high availability, great performance, unmatched security and more. You also get the power to easily connect your services to other Azure services, like Azure Cosmos DB and Azure Storage.
In this article, we'll get started with Azure Spring Cloud by creating a new Spring Cloud server in Azure and deploying a sample application to it.
If you want to follow along, you'll need the following:
Let's get started. We'll use a sample application, that you can find here, and deploy that to a new Azure Spring Cloud service.
First, we'll create a new Azure Spring Cloud server:
Go to the Azure portal
Click the Create a resource button (the plus-sign in the top left corner)
Search for Azure Spring Cloud and click on the result to start creating a new Azure Spring Cloud
a. This brings you to the create Azure Spring Cloud blade
b. Select a Resource group
c. Fill in a Name for the Spring Cloud
d. Select a Region
e. Click Review and create and Create after that to create the Azure Spring Cloud server
(Create new Azure Spring Cloud in the Azure portal)
Once the deployment is complete, we need to configure the Spring Cloud server, before we can start deploying applications to it.
(Setup the Azure Spring Cloud configuration server in the Azure portal)
Let's switch to the command prompt to download and compile the application and deploy it to the Azure Spring Cloud server. Make sure that you have installed everything from the prerequisites section.
First, we need to install the Azure Spring Cloud extension for the Azure CLI by running the following command:
az extension add --name spring-cloud
Next, run the following commands to download the code for the sample application:
mkdir source-code cd source-code git clone https://github.com/Azure-Samples/piggymetrics
And now compile the code using Maven:
cd piggymetrics mvn clean package -DskipTests
The code is compiled into .JAR files that we can deploy. Sign into Azure using the Azure CLI, so that we can start creating applications:
# Login to Azure CLI az login # List all subscriptions az account list -o table # Set active subscription az account set --subscription <target subscription ID>
Before we start using to the Azure Spring Cloud server we should assign names to the resource group and Spring Cloud server. The Azure CLI Spring CLoud extension uses these values. Make sure to put your values into the placeholders:
az configure --defaults group=<resource group name> az configure --defaults spring-cloud=<service instance name>
Now, we can create the applications in Azure Spring Cloud. With the following code, we create apps in Azure Spring Cloud and deploy JAR files to them. This will take several minutes to complete.
az spring-cloud app create -n gateway az spring-cloud app deploy -n gateway --jar-path ./gateway/target/gateway.jar az spring-cloud app create -n account-service az spring-cloud app deploy -n account-service --jar-path ./account-service/target/account-service.jar az spring-cloud app create -n auth-service az spring-cloud app deploy -n auth-service --jar-path ./auth-service/target/auth-service.jar
Let's go back to the Azure portal.
(Azure Spring Cloud apps in the Azure portal)
(Assign domain to Azure Spring Cloud app in the Azure portal)
Take the URL of the public endpoint and try it out in a browser. This should show the working application.
(The working application in a browser)
If you are developing Spring Boot-based-services and applications, you can run them in Azure Spring Cloud. Azure Spring Cloud is easy to setup, is managed by Azure, is highly available, performant and secure and enables you to connect your apps to Azure services like Azure Cosmos DB and Azure Storage. Go and check it out!