Skip to content

Commit 7d71373

Browse files
committed
README.md
1 parent 9c14f47 commit 7d71373

File tree

7 files changed

+60
-3
lines changed

7 files changed

+60
-3
lines changed

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
11

2+
# Spring Cloud Microservices sample
3+
To learn Spring Cloud Microservices and other spring modules, I took code from few samples available in net and clubbed together and pushed it into my git repo to avoid data loss.
4+
5+
## Environment Details
6+
Maven, Java8, Spring, Spring boot
7+
8+
## Architecture
9+
Our sample microservice application having following modules:
10+
### 1) Config Server
11+
- **config-service**
12+
- A Spring Boot application which uses Spring Cloud Config Server. *@EnableConfigServer* makes the application as Cloud Config Server. This server should be started first to make other services configuration files ready.
13+
- It has environment specific configuration files for other services(discovery-service,student-service, etc). Those files should be in git repositary to utilize the actual purpose of config server. Is there any change in properties, we no need to restart any of the servers. Need to change the properties & push to git repo. After successfull commit we need to reload cache from our business service, where this change should be reflect.
14+
- In My case I updated *environment.details* property in *department-service*.
15+
Beans which are using that properties should be annotated with *@RefreshScope* and to reload the cache we need to hit **/actuator/refresh** with post method. We can understand better by going through *department-service's* dependencies & **DepartmentController** file.
16+
17+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/ConfigServer.png" title="Config server setup"><br/>
18+
### 2) Netflix Eureka server
19+
- **discovery-service** - A Spring Cloud Netflix Eureka embedded discovery server. *@EnableEurekaServer* makes the application as Eureka embedded discovery server and in config file need to ensure *eureka.client.registerWithEureka = false, eureka.client.fetchRegistry = false*
20+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/DiscoveryServerConf.png" title="Discovery server setup"><br/>
21+
### 3) DiscoveryClients or Netflix Eureka clients
22+
*@EnableDiscoveryClient* makes the application as Discovery Client where this will be registered with our Netflix Eureka server by adding this config eureka.client.serviceUrl.defaultZone=http://localhost:8061/eureka/, **http://localhost:8061** url is our Eureka server url. Following services are Eureka clients which are registered with our *discovery-service*.
23+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/DiscoveryClientConf.png" title="Discovery client setup"><br/>
24+
- **gateway-service** - A Spring Boot application that acts as a gateway in our architecture, which recives requests from clients and routes to appropriate services in our micro service.
25+
- **employee-service** - A Spring Boot application that allows to perform CRUD operation on h2 db using spring data r2dbc of employees.
26+
- **student-service** - A Spring Boot application that allows to perform CRUD operation on h2 db using spring data r2dbc of students.
27+
- **department-service** - A Spring Boot application that allows to perform CRUD operation on h2 db using spring data r2dbc of departments. It communicates with employee-service.
28+
- **college-service** - A Spring Boot application that allows to perform CRUD operation on h2 db using spring data r2dbc of organizations. It communicates with both employee-service and department-service.
29+
Here is the Discovery server dashboard. Instances currently registered with our Eureka Discovery server and their statuses
30+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/DiscoveryServer.png" title="Server status"><br/>
31+
32+
### 4) Custom lib
33+
- **common-utils** - Logger aspect is common for all service. So Generic logger aspect library designed & added in all the services. In future any common things needed for all the business services, we can add it in this common-utils and we can make use of it.
34+
35+
## Tools and Technologies used
36+
- Java 8
37+
- Lombok pluging
38+
- Maven
39+
- Spring
40+
### In Spring following modules we used to explore those
41+
- **AOP** : To log the request/ response from client and request/response which we sent to other external server.
42+
- **Actuator** : To enable **/actuator/refresh** for relaoding cache. And there are lots of endpoints are there in spring we can check here [actuator](https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html).
43+
- **Cloud** : For over all microservice architecture.
44+
- **Data r2dbc** : Similar to spring data jpa which fetches the data in reactive way. Since we are using web-flux(non-blocling), we should not go with normal Spring data jpa. Since all are small service with single table we didn't explore one-one, one-many, many-one, many-many mappings.
45+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/R2DbcConfig.PNG" title="R2Dbc config"><br/>
46+
- **Exception Handler** : Yet to do.
47+
- **H2 DB** : Instead of keeping in cache, I used h2 DB to learn basics in spring data r2dbc. Instead of keeping as inmemory DB I stored it in local file to avoid data loss.
48+
- **Logs** : Logback used to log.
49+
- **Profile** : Spring profile used for different environment configuration. Also to run our application we need to add env valiable as shown.
50+
- *spring.profiles.active* dev or prod. Based on profile we have done logics in department-service
51+
- *username* db username.
52+
- *password* db password. Db credentials should be from environment variables for security purpose.
53+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/EnvVariables.PNG" title="Environment Variables"><br/>
54+
- **Swagger** : springdoc-openapi dependency used. Should not add any dependencied other than these dependencies shown for swagger for web-flux.
55+
<img src="https://github.com/prasath116/spring-reactive-micro-service/blob/master/readme-images/Swagger-dependency.PNG" title="Swagger dependency"><br/>
56+
Swagger Ui can be accessed via default swagger-ui endpoint /swagger-ui.html. For department-service it will be http://localhost:8060/department/swagger-ui.html . With this inbuild swager ui we can proceed our test instead of going for postman or any other test client or testing tools.
57+
- **WebFlux** : To achieve non blocking I/O we are using spring 5 webflux & projectreactor. Flux for more than on object as response and Mono for single object as response. We should not add *spring-boot-starter-web* instead we need to add *spring-boot-starter-webfluxFlux* dependency.
58+
Defeult server for *spring-boot-starter-webfluxFlux* is netty, which is non-blocking server.
59+
Defeult server for *spring-boot-starter-web* is tomcat.
60+
- **WebClient** : Spring 5 reactive WebClient used for non blocking client call to connect to external server.

reactive-micro-service/config-service/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ spring:
1111
git:
1212
uri: https://github.com/prasath116/cloud-config
1313
try-master-branch: true
14+
search-paths: cloud-reactive-configs
1415
# clone-on-start: true
1516
# default-label: main
16-
search-paths: cloud-reactive-configs
1717
#eureka:
1818
# client:
1919
# serviceUrl:

reactive-micro-service/department-service/src/main/java/com/prs/services/DepartmentApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6-
import org.springframework.cloud.openfeign.EnableFeignClients;
76
import org.springframework.context.annotation.Bean;
87
import org.springframework.core.io.ClassPathResource;
98
import org.springframework.data.r2dbc.connectionfactory.init.ConnectionFactoryInitializer;
@@ -15,7 +14,6 @@
1514

1615
@SpringBootApplication
1716
@EnableDiscoveryClient
18-
@EnableFeignClients
1917
@EnableWebFlux
2018
public class DepartmentApplication {
2119

readme-images/ConfigServer.png

6.35 KB
Loading
39.2 KB
Loading

readme-images/R2DbcConfig.png

41.3 KB
Loading
11.2 KB
Loading

0 commit comments

Comments
 (0)