Deploying Spring Boot microservices with Azure Spring Cloud

Radek Grębski
Nov 5, 2019 · 3 min read

Recently Microsoft announced Azure Spring Cloud project. In cooperation with Pivotal, they created a platform that makes a microservices application using Spring Cloud deployment very easy. It has been released today, so let’s try it!

Let’s start with setting up Azure CLI:

Login and setup subscription:

az login     
az account list -o table
az account set --subscription <SUBSCRIPTION_ID>

Add Azure Spring Cloud CLI extension:

az extension add --name spring-cloud

Create a resource group, provision an instance of Azure Spring Cloud and set them as defaults:

az group create --location westeurope --name spring-cloud-fun-group
az spring-cloud create -n spring-cloud-fun -g spring-cloud-fun-group
az configure --defaults group=spring-cloud-fun-group
az configure --defaults spring-cloud=spring-cloud-fun

Config server setup

For deployment, we are going to use Piggymetrics sample project from Azure Samples (it’s a fork of the original piggymetrics project).
First, we need to update config-server:

az spring-cloud config-server git set -n spring-cloud-fun --uri https://github.com/Azure-Samples/piggymetrics --label config

That’s it, we have configuration server set up. The command above made config server use config branch of the Piggybank git repository.
The branch contains only config YAML files for all the services (account-service.yml, application.yml, auth-service.yml, gateway.yml).
When setting up properties for services in gonfig server be aware that Azure injects following properties automatically and should not be used manually in config files:

eureka.client.service-url.defaultZone
eureka.client.tls.keystore
server.port
spring.cloud.config.tls.keystore
spring.application.name

Build the project and deploy

Checkout project and build:

git clone https://github.com/Azure-Samples/piggymetrics
cd PiggyMetrics
mvn clean package -DskipTests

Create microservices:

az spring-cloud app create --name gateway
az spring-cloud app create --name auth-service
az spring-cloud app create --name account-service

Deploy:

az spring-cloud app deploy -n gateway --jar-path ./gateway/target/gateway.jar
az spring-cloud app deploy -n account-service --jar-path ./account-service/target/account-service.jar
az spring-cloud app deploy -n auth-service --jar-path ./auth-service/target/auth-service.jar

Make the gateway public and get its public URL:

az spring-cloud app update -n gateway --is-public true
az spring-cloud app show --name gateway | grep url

In response, you should get URL like https://spring-cloud-fun-gateway.azuremicroservices.io/
If you open it, you should see the Piggy Metrics login page:

Distributed Tracing

Once the application is deployed we can easily enable Distributed Tracing in Azure Portal. It shows communication and dependencies between microservices. In our case it looks like this:

Summary

That’s it, deployment of three Spring Cloud microservices takes about
20 minutes, where most of the time is consumed by environment provisioning. Config, discovery, logging, monitoring, alerting and distributed tracing services are provided out of the box so a lot of infrastructure does not have to be set up manually.

Azure Spring Cloud was released officially today. It looks promising and is definitely worth looking at, especially when you want to quick start with Spring Cloud.

Stepwise

Radek Grębski

Written by

Stepwise

Stepwise

Stepwise is your product and software development partner. We offer: Product Design, Google Cloud Platform services, Data Analytics & Machine Learning, Software for Energy, Microservices Architecture. Main tech stack: GCP, Java, Kotlin, Node.js, React, Angular, Vue.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade