Microservice is becoming a popular
choice for implementing applications that need to be highly scalable,
deployable, reliable, etc. Many organizations have slowly started moving
towards Microservices architecture based applications.
Early adopters of microservices
are Netflix, Amazon, Uber, LinkedIn, Twitter, etc. Netflix also contributed
heavily to the developer community by outsourcing their microservices
solutions.
Spring framework provides required
components for implementing microservices in a simpler way.
In this course, we will discuss
creating, packaging, and deploying microservices using Spring Boot and Spring
Cloud components.
Demos |
Spring Version |
Remarks |
Demos shown in
videos |
Spring Boot -
1.5.8.RELEASE and Cloud Version is Dalston.RELEASE |
|
Demos on Cloud
Config, Ribbon, Hystrix API's that are available for download |
Spring
Boot-2.5.3 and Cloud Version is 2020.0.3 |
Upgraded to the
latest version |
Demos on Zuul,
and Zipkin APIs that are available for download |
Zuul and Zipkin
server microservices use Spring Boot-2.3.9.RELEASE and Cloud Version is
Hoxton.SR6. But the other microservices are upgraded to use the latest Zipkin
client libraries. |
As these
libraries are no longer supported and maintained by Spring Cloud. |
Demos on
Consul, Spring cloud LoadBalancer, Spring cloud Gateway, Resillience4j, and
Prometheus APIs that are available for download |
Spring Boot -
2.3.2.RELEASE and Cloud Version is - Hoxton.SR6 |
|
Have you ever written an
application that looks like this?
presentation --> Business
--> Persistence --> Database
Do you deploy the entire
application as a single WAR file or JAR?
Disadvantage :
The Monolithic application was a
good solution for the requirements of earlier times.
But with recent needs for better
user experience, monolithic applications fail to deliver the following
functionalities:
Alternatives :
Microservice is an architectural
style. In this style, the application is made up of smaller ( or micro ) apps
that communicate with each other, through open protocols like HTTP.
Microservices are distributed in
nature. It can either decompose a monolithic app into a microservice or can
develop a microservice-based solution from the beginning.
The characteristics of
Microservices are that they are:
What is the difference between an
Orange and an Orange segment? You will find more similarities than differences.
The same is the case with SOA ( Service Oriented Architecture ) and
Microservices. You cannot talk about microservices without talking about SOA.
Microservices are fine-grained
SOA. An SOA has ESB ( Enterprise Service Bus ) whereas Microservices have a
much simpler and direct communication mechanism.
Adrian Cockcroft at Netflix:
"We used to call the things we were building on the cloud "cloud-native"
or "fine-grained SOA," and then the ThoughtWorks people came up with
the word "microservices." It’s just another name for what we were
doing anyway, so we just started calling it microservices, as well. … You’re
trying to find words for things that resonate"
Steve Jones, MDM at Capgemini:
Microservices is SOA, for those who know what SOA is.
Similarities:
Differences:
If monolithic is bad, people would
not have been using it.
Monolithic has its advantages (if
it’s reasonable in size)* such as:
Microservices is a buzzword
technology gaining a lot of traction. Based on the need, competence, and size
of the applications, one may have to choose between Monolithic, SOA,
Microservice, etc.
Summary :
Application :
a telecom application called
InfyTel and delve into evolving this app from its monolithic architecture to a
full-fledged microservice version in multiple stages.
The first stage of the application
is its monolithic version.
What are some of the alternatives in placing the configuration details?
An ideal solution would be to use an external version control system like GIT, as it not only avoids the above-mentioned problems but also gives traceability of changes.
In the next stage of our application, let us use Cloud Config to access our configurations from GIT.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Configuring properties of Spring Cloud Config Server
When Cloud-Config is used, each microservice gets two properties files with the name 'application.properties'. One in GIT and the other one present locally. Which one will take precedence?
To ensure that the properties file from GIT takes higher priority, it needs to be accessed first before the local properties file for which the bootstrap context is used.
Spring Cloud creates a parent context to the spring application context called the ‘bootstrap’ context. This context takes precedence over the application context. This context is responsible for loading configuration details from an external source. Both these contexts share the Spring Environment, thus making configuration usage seamless.
Since the bootstrap context takes precedence the URI of the config-server must be mentioned in bootstrap.properties/YAML for the clients.
Note:
In the recent releases of Spring Boot versions >2.4.x, the bootstrap context initialization using property sources like bootstrap.properties/bootstrap.yml is deprecated.
As the demos are using Spring Boot 2.5.3 version we can add these configuration data to the application.properties file itself. No need for additional bootstrap.properties.
Also, the property to be added in the microservices is modified in recent releases as spring.config.import=optional:configserver:http://localhost:1111. Refer to the downloaded demos for the complete code.
To connect to the Infygithub/Github instead of the password we can also use the Personal Access Token. The access token can be generated from -> Settings -> Developer Settings -> Personal Access Tokens
Spring uses Environment to get the configuration details from various sources such as the environment variables, properties files, YAML files, etc. These are built in property sources. When we use cloud config, it adds an additional property source to the Environment such that it takes the properties from the cloud config server.
When cloud config is used, the additional property source takes a higher priority. It means that, any duplicate properties in other property sources are ignored.
We can access the configuration files by using endpoint on the config server in any one of the below patterns:
http://<config_server_host>:<port>:/<application>-<profile>.yml
http://<config_server_host>:<port>/<application>-<profile>.properties
The properties file used in the GIT must have the same name as that of the client's spring.application.name
spring.application.name = CallDetailsMS
Notes:
If you want to start an instance of Friend FamilyMS on a different port use the following command after the maven build of your project is done.
List: Link tgs Dropdown