Microservice Architecture with Azure Spring Cloud

Anil G.
3 min readJul 24, 2020

As Microsoft has vast documentation on how to do each part of the components used in my architecture, I’ll focus more on the quick setup of deploying your local apps to azure spring cloud.

Microservices Architecture
Application UI

The Microservices Architecture showed here, is to build a Directory App which is basically for searching users through azsc-search-directory-service where data will be populated from 3 possible options but not limited to Azure Cache layer/ Azure Postgres Replica / Simple Feign Client (to pull data from existing microservice). In this tutorial, User's data is pumped with data.sql from azsc-user-directory-service (ideally they can be added through Admin UI with POST call to the API, and assume data grows exponentially) and gets persisted in Azure Postgres. Out of those 3 options, I choose Feign Client, so that we don’t deviate much with other Azure components, rather focus more on understanding Azure Spring Cloud components. Also, Gateway is used for static resources (for quick UI) and routing in this tutorial. Azure Vault is the best place to keep the credentials, which is out of scope for this tutorial.

0. Pre-requisites

To understand pre-requisites (may take 10 mins), versions used in this tutorial please go through this page https://github.com/whyaneel/azure-spring-cloud-demo/wiki/Kickstart

—Checkout Code

git clone https://github.com/whyaneel/azure-spring-cloud-demo.git

—Quickly Load Env Variables
After you add your Azure Subscription ID to the following script, just run it so that all vars used in tutorial will be loaded

source ./setup_env_variables.sh

1. Azure Resources Creation

Create Resource Group and Azure Spring Cloud Instance

az account set --subscription “$SUBSCRIPTION_ID”az group create -g “$RESOURCE_GROUP_NAME” -l “$REGION_NAME”az spring-cloud create -g “$RESOURCE_GROUP_NAME” -n “$SPRING_CLOUD_NAME”

Create Config Server in Azure Spring Cloud
Use Azure Web Portal to map Github repo azsc-config-server to the config server. For Simplicity, I’ve generated config-server-import.yml file where we’ll mention SpringCloudConfigServerGit- Uri, Username, and Password (Github PAT) and import this in Azure Web Portal under Spring Cloud > Config Server

Create Azure Database for Postgres
Follow Steps mentioned in (execute one-by-one)

./setup_azure_postgres.sh

2. Create Apps (Microservices) in Spring Cloud

az spring-cloud app create -n azsc-user-directory-serviceaz spring-cloud app create -n azsc-search-directory-serviceaz spring-cloud app create -n azsc-gateway --is-public true

3. Deploy Apps to Spring Cloud

—Compiled Jars are added (so you can just focus on deploying the apps to Azure Spring Cloud), Ideally one has to develop these applications.

az spring-cloud app deploy -n azsc-user-directory-service --jar-path ./azsc-user-directory-service/build/libs/azsc-user-directory-service-0.0.1-SNAPSHOT.jaraz spring-cloud app deploy -n azsc-search-directory-service --jar-path ./azsc-search-directory-service/target/azsc-search-directory-service-0.0.1-SNAPSHOT.jaraz spring-cloud app deploy -n azsc-gateway --jar-path ./azsc-gateway/target/azsc-gateway-0.0.1-SNAPSHOT.jar

4. Access User Directory Management App

If you followed other namings for spring-cloud and gateway, change the below URLs accordingly. That’s why I made them non-clickable.

UI — https://azsc-from-paloit-azsc-gateway.azuremicroservices.io/index.html

API — https://azsc-from-paloit-azsc-gateway.azuremicroservices.io/api/admin/users

API — https://azsc-from-paloit-azsc-gateway.azuremicroservices.io/api/search/users

Note that above APIs will route to respective Microservices as per Routing

5. Cleanup Resources

—This is to save cost on resources, clean up all resources in one shot once you’re done with the tutorial

az group delete --name $RESOURCE_GROUP_NAME --yes

Looking for Detailed Approach, see below

Code Availablehttps://github.com/whyaneel?tab=repositories&q=azsc

--

--

Anil G.

I’m a coding enthusiast and love to work in complex systems & agile driven projects. My work can be found at https://github.com/whyaneel