TIP

🔥 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.

Develop Microservice-based apps 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.

Prerequisites

If you want to follow along, you'll need the following:

Getting started with Azure Spring Cloud

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:

  1. Go to the Azure portal

  2. Click the Create a resource button (the plus-sign in the top left corner)

  3. 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.

  1. In the Azure portal, open the newly created Azure Spring Cloud server
  2. Go to the Config Server menu
  3. Under Default repository, set the URI value to https://github.com/Azure-Samples/piggymetrics and the Label value to config
  4. Click Apply

(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
1

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
1
2
3

And now compile the code using Maven:

cd piggymetrics
mvn clean package -DskipTests
1
2

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>
1
2
3
4
5
6
7
8

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>
1
2

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
1
2
3
4
5
6

Let's go back to the Azure portal.

  1. Go to the Azure Spring Cloud server
  2. Click on the Apps menu. This should show three applications. These are three microservice applications that make up the solution

(Azure Spring Cloud apps in the Azure portal)

  1. Click on the gateway app. We need to assign a domain to this, so that we can access it from the internet
  2. In the next screen, click on the Assign domain button. This will take a few minutes to complete

(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)

Conclusion

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!