Skip to content

Commit b673db6

Browse files
committed
Merge branch 'release/3.0'
2 parents 4722375 + 739cdae commit b673db6

File tree

68 files changed

+2429
-746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2429
-746
lines changed

README.md

+62-46
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
------
88

99
I am developing this project as stages, and all such stages are documented under project
10-
**Springy Store μServices** [wiki page](https://github.com/mohamed-taman/Springy-Store
11-
-Microservices/wiki). Each of such stage will be a release in its owen, so you can go back and
10+
**Springy Store μServices** [wiki page](https://github.com/mohamed-taman/Springy-Store-Microservices/wiki). Each of such stage will be a release in its owen, so you can go back and
1211
forward
1312
between releases to see the differences and how adding things solve specific problems we face.
1413

1514
For example; in the first stage (1st release) I just created project structure, basic services' skeleton, integration between them, and finally write integration testing as well as semi-automated testing for the whole services' functionality.
1615

17-
At 1st stage the **recommendation** and **review** microservices generate local in-memory data and **product composite service** calls the other three services (*product*, *recommendation*, and *review*) statically to generate client aggregate response for a specific product. Therefore, in:
16+
At 1st stage the **Recommendation** and **Review** microservices generate local in-memory data
17+
and **Store Service** calls the other three services (*Product*, *Recommendation*, and *Review*) statically to generate client aggregate response for a specific product. Therefore, in:
1818

19-
- The second stage I will introduce **database integration**, then in
20-
- The third stage I will introduce **Dockerization** of our services and **docker-compose**, and in
19+
- The second stage I will introduce **database integration**, then in (***done***)
20+
- The third stage I will introduce **Dockerization** of our services and **docker-compose**, and in (***done***)
2121
- The fourth stage I will introduce **service discovery**, and so on.
2222

2323
## Getting started
@@ -33,19 +33,19 @@ The following topics are going to be covered in this 1st stage (other stages top
3333
- Introducing the microservice landscape.
3434
- Generating skeleton microservices.
3535
- Adding RESTful APIs.
36-
- Adding a **product composite**, **product**, **recommendation**, and **review** microservices.
36+
- Adding a **Store**, **Product**, **Recommendation**, and **Review** microservices.
3737
- Adding error handling.
3838
- Testing the APIs manually.
3939
- Adding automated tests of microservices in isolation.
4040
- Adding semi-automated tests to a microservice landscape.
4141

42-
### System Boundary - μServices Landscape
42+
### System Boundary - μServices Landscape (Release 3)
4343

4444
![System Boundary](docs/stage1/app_ms_landscape.png)
4545

4646
### Required software
4747

48-
The following software pieces are initially required:
48+
The following are the initially required software pieces:
4949

5050
1. **Git**: it can be downloaded and installed from https://git-scm.com/downloads.
5151

@@ -57,6 +57,8 @@ The following software pieces are initially required:
5757

5858
5. Spring Boot Initializer: This *Initializer* generates *spring* boot project with just what you need to start quickly! start from here https://start.spring.io/.
5959

60+
6. **Docker Desktop**: The fastest way to containerize applications on your desktop, and you can download it from here [https://www.docker.com/products/docker-desktop](https://www.docker.com/products/docker-desktop)
61+
6062
> For each future stage, I will list the newly required software.
6163
6264
Follow the installation guide for each software website and check your software versions from the command line to verify that they are installed correctly.
@@ -85,7 +87,9 @@ To build and run test cases for each service & shared modules in the project we
8587

8688
> This done only for the first time or any new version of shared modules.
8789
88-
To build and install `store-utils`, `store-api`, `store-chassis` libraries, from the root folder `springy-store-microservices` run the following commands:
90+
To build and install `store-build-chassis`, `store-utils`, `store-api`, `store-chassis` libraries
91+
, from the root
92+
folder `springy-store-microservices` run the following commands:
8993

9094
```bash
9195
mohamed.taman@DTLNV8 ~/springy-store-microservices
@@ -98,16 +102,16 @@ Now you should expect output like this:
98102
Installing all Springy store core shared modules
99103
................................................
100104

101-
1- Installing [build parent] module...
105+
1- Installing [Parent Build Chassis] module...
102106
Done successfully.
103107

104-
2- Installing shared [Utilities] module...
108+
2- Installing shared [Services Utilities] module...
105109
Done successfully.
106110

107-
3- Installing shared [APIs] module...
111+
3- Installing shared [Services APIs] module...
108112
Done successfully.
109113

110-
4- Installing [service parent] module...
114+
4- Installing [Services Parent Chassis] module...
111115
Done successfully.
112116

113117
Woohoo, building & installing all project modules are finished successfully.
@@ -120,7 +124,7 @@ Now it is time to build our **4 microservices** and run each service integration
120124

121125
```bash
122126
mohamed.taman@DTLNV8 ~/springy-store-microservices
123-
λ ./mvnw clean verify
127+
λ ./mvnw clean verify -Ddockerfile.skip
124128
```
125129

126130
All build commands and test suite for each microservice should run successfully, and the final output should be like this:
@@ -138,7 +142,7 @@ All build commands and test suite for each microservice should run successfully,
138142
[INFO] Springy Store APIs ................................. SUCCESS [ 3.920 s]
139143
[INFO] Springy Store Utils ................................ SUCCESS [ 1.508 s]
140144
[INFO] Springy Store Chassis .............................. SUCCESS [ 0.608 s]
141-
[INFO] Product Composite Service .......................... SUCCESS [ 4.073 s]
145+
[INFO] Store Service ...................................... SUCCESS [ 4.073 s]
142146
[INFO] Product Service .................................... SUCCESS [ 2.710 s]
143147
[INFO] Review Service ..................................... SUCCESS [ 2.633 s]
144148
[INFO] Recommendation Service ............................. SUCCESS [ 2.615 s]
@@ -152,37 +156,55 @@ All build commands and test suite for each microservice should run successfully,
152156
```
153157

154158
### Running Them All
155-
Now it's the time to run all of them, and it's very simple just run the following two commands:
159+
Now it's the time to run all of them, and it's very simple just run the following *<u>docker compose</u>* commands:
156160

157161
```bash
158162
mohamed.taman@DTLNV8 ~/springy-store-microservices
159-
λ ./run-em-all.sh
163+
λ docker-compose -p ssm up -d
164+
```
165+
166+
All the **services** and **databases** will run in parallel in detached mode (option `-d`), and their output will be printed to the console as the following:
167+
168+
```bash
169+
Creating network "ssm_default" with the default driver
170+
Creating ssm_mysql_1 ... done
171+
Creating ssm_mongodb_1 ... done
172+
Creating ssm_store_1 ... done
173+
Creating ssm_review_1 ... done
174+
Creating ssm_product_1 ... done
175+
Creating ssm_recommendation_1 ... done
160176
```
161177

162-
All the services will run in parallel, and their output will be printed to the console.
178+
### Access Store APIs
179+
You can manually test `Store Service` APIs through out its **Swagger** interface at the following
180+
URL [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html).
163181

164182
### Testing Them All
165-
Now it's time to test all functionality of the application as one part. To do so just run
183+
Now it's time to test all the application functionality as one part. To do so just run
166184
the following automation test script:
167185

168186
```bash
169187
mohamed.taman@DTLNV8 ~/springy-store-microservices
170-
λ PORT=9080 ./test-em-all.sh
188+
λ ./test-em-all.sh
171189
```
172190

173191
The result should be something like this:
174192

175193
```bash
176194
Starting [Springy Store] full functionality testing....
177195

196+
Start: Sun, Apr 12, 2020 2:34:19 PM
178197
HOST=localhost
179-
PORT=9080
198+
PORT=8080
199+
Wait for: curl -X DELETE http://localhost:8080/store/api/v1/products/13... Ok
200+
Test OK (HTTP Code: 200)
201+
Test OK (HTTP Code: 200)
202+
Test OK (HTTP Code: 200)
180203
Test OK (HTTP Code: 200)
181204
Test OK (actual value: 1)
182205
Test OK (actual value: 3)
183206
Test OK (actual value: 3)
184-
Test OK (HTTP Code: 404, {"httpStatus":"NOT_FOUND","message":"No product found for productId: 13
185-
","path":"/v1/product-composite/13","time":"2020-04-01@14:51:48.812+0200"})
207+
Test OK (HTTP Code: 404, {"httpStatus":"NOT_FOUND","message":"No product found for productId: 13","path":"/store/api/v1/products/13","time":"2020-04-12@12:34:25.144+0000"})
186208
Test OK (HTTP Code: 200)
187209
Test OK (actual value: 113)
188210
Test OK (actual value: 0)
@@ -191,12 +213,11 @@ Test OK (HTTP Code: 200)
191213
Test OK (actual value: 213)
192214
Test OK (actual value: 3)
193215
Test OK (actual value: 0)
194-
Test OK (HTTP Code: 422, {"httpStatus":"UNPROCESSABLE_ENTITY","message":"Invalid productId: -1
195-
","path":"/v1/product-composite/-1","time":"2020-04-01@14:51:49.763+0200"})
216+
Test OK (HTTP Code: 422, {"httpStatus":"UNPROCESSABLE_ENTITY","message":"Invalid productId: -1","path":"/store/api/v1/products/-1","time":"2020-04-12@12:34:26.243+0000"})
196217
Test OK (actual value: "Invalid productId: -1")
197-
Test OK (HTTP Code: 400, {"timestamp":"2020-04-01T12:51:49.965+0000","path":"/v1/product-composite
198-
/invalidProductId","status":400,"error":"Bad Request","message":"Type mismatch."})
218+
Test OK (HTTP Code: 400, {"timestamp":"2020-04-12T12:34:26.471+00:00","path":"/store/api/v1/products/invalidProductId","status":400,"error":"Bad Request","message":"Type mismatch.","requestId":"044dcdf2-13"})
199219
Test OK (actual value: "Type mismatch.")
220+
End: Sun, Apr 12, 2020 2:34:26 PM
200221
```
201222

202223
### Closing The Story
@@ -206,30 +227,25 @@ Finally, to close the story, we will need to shut down Microservices manually se
206227

207228
```bash
208229
mohamed.taman@DTLNV8 ~/springy-store-microservices
209-
λ ./stop-em-all.sh
230+
λ docker-compose -p ssm down
210231
```
211232

212233
And the output should be as the following:
213234

214235
```bash
215-
Stopping [Springy Store] μServices ....
216-
---------------------------------------
217-
218-
Stopping Microservice at port 9080 ....
219-
{"message":"Shutting down, bye..."}
220-
Microservice at port 9080 stopped successfully ....
221-
222-
Stopping Microservice at port 9081 ....
223-
{"message":"Shutting down, bye..."}
224-
Microservice at port 9081 stopped successfully ....
225-
226-
Stopping Microservice at port 9082 ....
227-
{"message":"Shutting down, bye..."}
228-
Microservice at port 9082 stopped successfully ....
229-
230-
Stopping Microservice at port 9083 ....
231-
{"message":"Shutting down, bye..."}
232-
Microservice at port 9083 stopped successfully ....
236+
Stopping ssm_recommendation_1 ... done
237+
Stopping ssm_product_1 ... done
238+
Stopping ssm_review_1 ... done
239+
Stopping ssm_mongodb_1 ... done
240+
Stopping ssm_store_1 ... done
241+
Stopping ssm_mysql_1 ... done
242+
Removing ssm_recommendation_1 ... done
243+
Removing ssm_product_1 ... done
244+
Removing ssm_review_1 ... done
245+
Removing ssm_mongodb_1 ... done
246+
Removing ssm_store_1 ... done
247+
Removing ssm_mysql_1 ... done
248+
Removing network ssm_default
233249
```
234250

235251
### The End

docker-compose.yml

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,58 @@
1-
version: '2.1'
1+
version: '3.7' ## Latest version works with Docker Engine release 18.06.0+
22

33
services:
44
product:
55
build: product-service
6-
mem_limit: 350m
76
environment:
87
- SPRING_PROFILES_ACTIVE=docker
8+
depends_on:
9+
- mongodb
910

1011
recommendation:
1112
build: recommendation-service
12-
mem_limit: 350m
1313
environment:
1414
- SPRING_PROFILES_ACTIVE=docker
15+
depends_on:
16+
- mongodb
1517

1618
review:
1719
build: review-service
18-
mem_limit: 350m
1920
environment:
2021
- SPRING_PROFILES_ACTIVE=docker
22+
depends_on:
23+
- mysql
2124

22-
product-composite:
23-
build: product-composite-service
24-
mem_limit: 350m
25+
store:
26+
build: store-service
2527
ports:
2628
- "8080:8080"
2729
environment:
2830
- SPRING_PROFILES_ACTIVE=docker
31+
32+
# $ mongo
33+
mongodb:
34+
image: mongo:4.2.5-bionic
35+
ports:
36+
- "27017-27019:27017-27019"
37+
healthcheck:
38+
test: echo 'db.runCommand("ping").ok' | mongo mongo:27017/test --quiet 1
39+
interval: 10s
40+
timeout: 10s
41+
retries: 5
42+
start_period: 40s
43+
44+
# $ mysql -uroot -h127.0.0.1 -p
45+
mysql:
46+
image: mysql:8.0.19
47+
ports:
48+
- "3306:3306"
49+
environment:
50+
- MYSQL_ROOT_PASSWORD=rootpwd
51+
- MYSQL_DATABASE=review-db
52+
- MYSQL_USER=user
53+
- MYSQL_PASSWORD=pwd
54+
healthcheck:
55+
test: ["CMD", "mysqladmin" ,"ping", "-uuser", "-ppwd", "-h", "localhost"]
56+
interval: 10s
57+
timeout: 5s
58+
retries: 10

docs/stage1/app_ms_landscape.png

-58.1 KB
Loading

pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
<maven.deploy.skip>true</maven.deploy.skip>
1717
</properties>
1818

19-
2019
<modules>
21-
<module>product-composite-service</module>
2220
<module>product-service</module>
2321
<module>review-service</module>
2422
<module>recommendation-service</module>
23+
<module>store-service</module>
2524
<module>store-api</module>
2625
<module>store-utils</module>
2726
<module>store-build-chassis</module>

product-composite-service/src/main/java/com/siriusxi/ms/store/pcs/controller/ProductCompositeServiceImpl.java

-85
This file was deleted.

0 commit comments

Comments
 (0)