From 4c94bde6ac53bf65f8f8e7fb3bcc8f73bd5e022d Mon Sep 17 00:00:00 2001 From: Sanjoy Kumer Deb Date: Sun, 26 Apr 2020 13:48:45 +0600 Subject: [PATCH] [ARticle code for microservices] --- microservice/.DS_Store | Bin 0 -> 6148 bytes microservice/configserver/.DS_Store | Bin 0 -> 6148 bytes microservice/configserver/pom.xml | 70 ++++++++++++++++++ .../configserver/ConfigserverApplication.java | 15 ++++ .../src/main/resources/application.properties | 6 ++ .../ConfigserverApplicationTests.java | 13 ++++ microservice/dicoveryserver/.DS_Store | Bin 0 -> 6148 bytes microservice/dicoveryserver/pom.xml | 69 +++++++++++++++++ .../DiscoveryserverApplication.java | 15 ++++ .../src/main/resources/application.properties | 5 ++ .../DiscoveryserverApplicationTests.java | 13 ++++ microservice/pom.xml | 55 ++++++++++++++ microservice/profilemanagement/.DS_Store | Bin 0 -> 6148 bytes microservice/profilemanagement/pom.xml | 66 +++++++++++++++++ .../ProfilemanagementApplication.java | 17 +++++ .../controller/EmployeeController.java | 26 +++++++ .../domain/EmployeeProfile.java | 32 ++++++++ .../service/EmployeeProfileService.java | 10 +++ .../service/EmployeeProfileServiceImpl.java | 22 ++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/bootstrap.properties | 3 + .../ProfilemanagementApplicationTests.java | 13 ++++ 22 files changed, 451 insertions(+) create mode 100644 microservice/.DS_Store create mode 100644 microservice/configserver/.DS_Store create mode 100644 microservice/configserver/pom.xml create mode 100644 microservice/configserver/src/main/java/com/ayoosh/configserver/ConfigserverApplication.java create mode 100644 microservice/configserver/src/main/resources/application.properties create mode 100644 microservice/configserver/src/test/java/com/ayoosh/configserver/ConfigserverApplicationTests.java create mode 100644 microservice/dicoveryserver/.DS_Store create mode 100644 microservice/dicoveryserver/pom.xml create mode 100644 microservice/dicoveryserver/src/main/java/com/ayoosh/discoveryserver/DiscoveryserverApplication.java create mode 100644 microservice/dicoveryserver/src/main/resources/application.properties create mode 100644 microservice/dicoveryserver/src/test/java/com/ayoosh/discoveryserver/DiscoveryserverApplicationTests.java create mode 100644 microservice/pom.xml create mode 100644 microservice/profilemanagement/.DS_Store create mode 100644 microservice/profilemanagement/pom.xml create mode 100644 microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/ProfilemanagementApplication.java create mode 100644 microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/controller/EmployeeController.java create mode 100644 microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/domain/EmployeeProfile.java create mode 100644 microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileService.java create mode 100644 microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileServiceImpl.java create mode 100644 microservice/profilemanagement/src/main/resources/application.properties create mode 100644 microservice/profilemanagement/src/main/resources/bootstrap.properties create mode 100644 microservice/profilemanagement/src/test/java/com/ayoosh/profilemanagement/ProfilemanagementApplicationTests.java diff --git a/microservice/.DS_Store b/microservice/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ce3a1d9c577ff9f413ff8da9ca50f8b3324e4244 GIT binary patch literal 6148 zcmeHK%WA_g5FE8B1bWG_M}0v<|G)(I7D}Py-ZaUfN#g{^cInNZ-q~HX#Kh-f$_k{B zW*?FUELi};tX@9=698jY!62QUB6P3mDme=V&9OXIZ}a+8l|5;ONy*x8aF2JavBCNJ z=UCuGu4Fr9U82Ai2Yhjq6IZCQr@cU>9?$e#lC79)MLt5917kMIN|ptV_#{_i$I+Jl z4Xe!DXzrSpg3Jf4d(9&mY!yw)JH1%(Q&RkFAHx*eSLF)00t ze8x?syY*swa@R)IS5_(F*Gh+l{mxGS2XcH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + microservice + com.ayoosh + 0.0.1-SNAPSHOT + + 4.0.0 + + configserver + + + 1.8 + Hoxton.SR3 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-jersey + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-config-server + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/microservice/configserver/src/main/java/com/ayoosh/configserver/ConfigserverApplication.java b/microservice/configserver/src/main/java/com/ayoosh/configserver/ConfigserverApplication.java new file mode 100644 index 0000000..4508206 --- /dev/null +++ b/microservice/configserver/src/main/java/com/ayoosh/configserver/ConfigserverApplication.java @@ -0,0 +1,15 @@ +package com.ayoosh.configserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + +@SpringBootApplication +@EnableConfigServer +public class ConfigserverApplication { + + public static void main(String[] args) { + SpringApplication.run(ConfigserverApplication.class, args); + } + +} diff --git a/microservice/configserver/src/main/resources/application.properties b/microservice/configserver/src/main/resources/application.properties new file mode 100644 index 0000000..5631ae9 --- /dev/null +++ b/microservice/configserver/src/main/resources/application.properties @@ -0,0 +1,6 @@ +server.port=8082 +spring.application.name=configserver +spring.cloud.config.server.git.uri = https://github.com/flopcoder82/microservices +spring.cloud.config.server.git.username=flopcoder82 +spring.cloud.config.server.git.password=Gitto@123 +spring.cloud.config.server.git.clone-on-start=true diff --git a/microservice/configserver/src/test/java/com/ayoosh/configserver/ConfigserverApplicationTests.java b/microservice/configserver/src/test/java/com/ayoosh/configserver/ConfigserverApplicationTests.java new file mode 100644 index 0000000..734d5bc --- /dev/null +++ b/microservice/configserver/src/test/java/com/ayoosh/configserver/ConfigserverApplicationTests.java @@ -0,0 +1,13 @@ +package com.ayoosh.configserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ConfigserverApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/microservice/dicoveryserver/.DS_Store b/microservice/dicoveryserver/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + microservice + com.ayoosh + 0.0.1-SNAPSHOT + + 4.0.0 + + dicoveryserver + + + 1.8 + Hoxton.SR3 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/microservice/dicoveryserver/src/main/java/com/ayoosh/discoveryserver/DiscoveryserverApplication.java b/microservice/dicoveryserver/src/main/java/com/ayoosh/discoveryserver/DiscoveryserverApplication.java new file mode 100644 index 0000000..9e30cb0 --- /dev/null +++ b/microservice/dicoveryserver/src/main/java/com/ayoosh/discoveryserver/DiscoveryserverApplication.java @@ -0,0 +1,15 @@ +package com.ayoosh.discoveryserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class DiscoveryserverApplication { + + public static void main(String[] args) { + SpringApplication.run(DiscoveryserverApplication.class, args); + } + +} diff --git a/microservice/dicoveryserver/src/main/resources/application.properties b/microservice/dicoveryserver/src/main/resources/application.properties new file mode 100644 index 0000000..618bd49 --- /dev/null +++ b/microservice/dicoveryserver/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.application.name=discoveryserver +server.port=8081 +eureka.client.register-with-eureka=false +eureka.client.fetch-registry=false + diff --git a/microservice/dicoveryserver/src/test/java/com/ayoosh/discoveryserver/DiscoveryserverApplicationTests.java b/microservice/dicoveryserver/src/test/java/com/ayoosh/discoveryserver/DiscoveryserverApplicationTests.java new file mode 100644 index 0000000..633f064 --- /dev/null +++ b/microservice/dicoveryserver/src/test/java/com/ayoosh/discoveryserver/DiscoveryserverApplicationTests.java @@ -0,0 +1,13 @@ +package com.ayoosh.discoveryserver; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DiscoveryserverApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/microservice/pom.xml b/microservice/pom.xml new file mode 100644 index 0000000..4b091e2 --- /dev/null +++ b/microservice/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + pom + + dicoveryserver + configserver + profilemanagement + + + org.springframework.boot + spring-boot-starter-parent + 2.2.6.RELEASE + + + com.ayoosh + microservice + 0.0.1-SNAPSHOT + microservice + Microservices with spring boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/microservice/profilemanagement/.DS_Store b/microservice/profilemanagement/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + microservice + com.ayoosh + 0.0.1-SNAPSHOT + + 4.0.0 + + profilemanagement + + + 1.8 + Hoxton.SR3 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/ProfilemanagementApplication.java b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/ProfilemanagementApplication.java new file mode 100644 index 0000000..c526616 --- /dev/null +++ b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/ProfilemanagementApplication.java @@ -0,0 +1,17 @@ +package com.ayoosh.profilemanagement; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; + +@SpringBootApplication +@EnableEurekaClient +@EnableDiscoveryClient +public class ProfilemanagementApplication { + + public static void main(String[] args) { + SpringApplication.run(ProfilemanagementApplication.class, args); + } + +} diff --git a/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/controller/EmployeeController.java b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/controller/EmployeeController.java new file mode 100644 index 0000000..8cf8117 --- /dev/null +++ b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/controller/EmployeeController.java @@ -0,0 +1,26 @@ +package com.ayoosh.profilemanagement.controller; + +import com.ayoosh.profilemanagement.domain.EmployeeProfile; +import com.ayoosh.profilemanagement.service.EmployeeProfileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping(value = "/") +public class EmployeeController { + @Autowired + EmployeeProfileService employeeProfileService; + + @PostMapping + public void saveEmployeeProfile(@RequestBody EmployeeProfile employeeProfile){ + employeeProfileService.addEmployeeProfile(employeeProfile); + } + + @GetMapping + public List getAllEmployee(){ + return employeeProfileService.getEmployeeProfiles(); + } + +} diff --git a/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/domain/EmployeeProfile.java b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/domain/EmployeeProfile.java new file mode 100644 index 0000000..9e8eefc --- /dev/null +++ b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/domain/EmployeeProfile.java @@ -0,0 +1,32 @@ +package com.ayoosh.profilemanagement.domain; + +public class EmployeeProfile { + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + private String name; + private String address; +} diff --git a/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileService.java b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileService.java new file mode 100644 index 0000000..0899f1c --- /dev/null +++ b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileService.java @@ -0,0 +1,10 @@ +package com.ayoosh.profilemanagement.service; + +import com.ayoosh.profilemanagement.domain.EmployeeProfile; + +import java.util.List; + +public interface EmployeeProfileService { + void addEmployeeProfile(EmployeeProfile profile); + List getEmployeeProfiles(); +} diff --git a/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileServiceImpl.java b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileServiceImpl.java new file mode 100644 index 0000000..298972a --- /dev/null +++ b/microservice/profilemanagement/src/main/java/com/ayoosh/profilemanagement/service/EmployeeProfileServiceImpl.java @@ -0,0 +1,22 @@ +package com.ayoosh.profilemanagement.service; + +import com.ayoosh.profilemanagement.domain.EmployeeProfile; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class EmployeeProfileServiceImpl implements EmployeeProfileService { + List employeeProfileList = new ArrayList<>(); + + @Override + public void addEmployeeProfile(EmployeeProfile profile) { + employeeProfileList.add(profile); + } + + @Override + public List getEmployeeProfiles() { + return employeeProfileList; + } +} diff --git a/microservice/profilemanagement/src/main/resources/application.properties b/microservice/profilemanagement/src/main/resources/application.properties new file mode 100644 index 0000000..56e8e97 --- /dev/null +++ b/microservice/profilemanagement/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=profilemanagement diff --git a/microservice/profilemanagement/src/main/resources/bootstrap.properties b/microservice/profilemanagement/src/main/resources/bootstrap.properties new file mode 100644 index 0000000..cc1bec3 --- /dev/null +++ b/microservice/profilemanagement/src/main/resources/bootstrap.properties @@ -0,0 +1,3 @@ +spring.cloud.config.uri=http://localhost:8082 +spring.cloud.config.name=profilemanagement +spring.cloud.config.profile=active \ No newline at end of file diff --git a/microservice/profilemanagement/src/test/java/com/ayoosh/profilemanagement/ProfilemanagementApplicationTests.java b/microservice/profilemanagement/src/test/java/com/ayoosh/profilemanagement/ProfilemanagementApplicationTests.java new file mode 100644 index 0000000..17d6b9a --- /dev/null +++ b/microservice/profilemanagement/src/test/java/com/ayoosh/profilemanagement/ProfilemanagementApplicationTests.java @@ -0,0 +1,13 @@ +package com.ayoosh.profilemanagement; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ProfilemanagementApplicationTests { + + @Test + void contextLoads() { + } + +}