COMP 301 Week 10
COMP 301 Week 10
Microservice Communication
Part 1
Understanding POM
● What is POM ?
● Super POM
● Minimal POM
● Project Inheritance
● Project Aggregation
● Project Variables / Properties
What is POM ?
Maven Project /
POM
Inherite
Super POM Maven Project /
d by
POM
All Maven
Minimal POM
Inherit Inherit
by POM have by
POM have
POM have X, Y,
Project B Project A Z Project B P
P (X, Y (X,Y
inherited) inherited)
Before Afte
Project Inheritance / Aggregation Impl.
Create 3 projects
● Parent project :: mvn archetype:generate -DgroupId=com.parent.app
-DartifactId=parent -DarchetypeArtifactId=maven-archetype-
quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
● Child module 1 :: mvn archetype:generate -DgroupId=com.child.app -
DartifactId=child-1 -DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeVersion=1.4 -DinteractiveMode=false
● Child module 2 :: mvn archetype:generate -DgroupId=com.child.app -
DartifactId=child-2 -DarchetypeArtifactId=maven-archetype-quickstart
-DarchetypeVersion=1.4 -DinteractiveMode=false
Inheritance : Directory Structure Type
1
Minimal Parent POM
Minimal Child POM
Inheritance : Directory Structure Type
2
Minimal Parent POM
Minimal Child POM
Project Aggregation
child-1(Module-1)POM have D, E
.
Aggregation : Directory Structure
Type 1
Minimal Parent POM
Minimal Child POM
Project Inheritance Vs Project
Aggregation
Property
usage
Microservice Communication
• We will look at how microservice can communicate with each other :
1.Synchronous Communication
2.Asynchronous Communication
Synchronous Communication
Synchronized Communication
• In Spring boot microservices can tale k with each other by 3 ways:
Using RestTemplate object(depreciated)
Using WebClient
Spring Cloud Open Feign library
Using RestTemplate
• In order to use RestTemplate object:
Instantiate RestTemplate object using @Bean annotation on the top of
method.
Inject generated RestTemplate object in Spring IOC container into related
Service class( either via constructor or @Autowired annotation)
RestTemplate class
• RestTemplate is Synchronous client to perform HTTP requests,
exposing a simple, template method API over underlying HTTP client
libraries such as the JDK HttpURLConnection, Apache
HttpComponents, and others.
• RestTemplate offers templates for common scenarios by HTTP
method, in addition to the generalized exchange and execute
methods that support less frequent cases.
RestTemplate usage
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
Example FeignClient Interface
• Furthermore, since this interface is a Feign client, we can use the Spring Web
annotations to declare the APIs that we want to reach out to.
• Finally, You just need to inject Feign Client in your required service.
Asynchronous Communication
Asynchronous Communication