December 02, 2019

Part 4: Microservices Demo

We will develop a microservice using Spring Cloud which will return details about all the departments that exist, along with all the employees working in a particular department.



Client will call getDetails API, which will internally fetch the department details by calling getDepartments API, and then call getEmployees API, consolidate the result and send it to client.

We will create three Spring Boot projects:
1). depart-employee-details (GIT Link)
2). department-details (GIT Link)
3). employee-details (GIT Link)

In the 'department-details', we will create a resource class 'DeptResource' inside com.scrutiny.departdetails.controller.

Configure the port in application.properties by adding 'server.port=8082'. Start the Spring Boot project and open the below URL in browser.

URL: http://localhost:8082/department/getDepartmentDetails

In the 'employee-details', we will create a resource class 'EmpResource' inside com.scrutiny.empdetails.controller.


Configure the port in application.properties by adding 'server.port=8083'. Start the Spring Boot project and open the below URL in browser.

URL:  http://localhost:8083/employee/getemployeeDetails/1

In the 'depart-employee-details', we will create a resource class 'DepEmpResource' inside com.scrutiny.departempdetails.controller.


Configure the port in application.properties by adding 'server.port=8081'. Start the Spring Boot project and open the below URL in browser.

URL:  http://localhost:8081/details/getDetails

getDetails will first fetch the department details, and then for each department fetch the employee details. Consolidate the results and return them.

Download the code till now from below GIT url:
GIT URL: microservices

-K Himaanshu Shuklaa..

No comments:

Post a Comment