|
1 |
| -# Springy Store Microservices |
2 |
| -This project is a development of a small set of Microservices spring boot based projects, that implement cloud-native recommendations to show how Microservices should be built, using the following cutting edge technologies like Docker, Kubernetes, Elasticsearch Stack, Java SE 14, MySQL database, MongoDB, and Reactive Programming, with many more. |
| 1 | +# Springy Store μServices |
| 2 | + |
| 3 | +- This project is a development of a small set of Spring Boot based Microservices projects, that implement cloud-native intuitive, design patterns and coding best practices. |
| 4 | +- The project follows [**CloudNative**](https://www.cncf.io/) recommendations and The [**twelve-factor app**](https://12factor.net/) methodology for building *software-as-a-service apps* to show how μServices should be built and deployed. |
| 5 | +- The project is using cutting edge technologies like Docker, Kubernetes, Elasticsearch Stack for logging and monitoring, Java SE 14, MySQL database, MongoDB, TDD, unit, integration & performance testing and Reactive Programming, and many more. |
| 6 | + |
| 7 | +------ |
| 8 | + |
| 9 | +I am developing this project as stages, and all such stages are documented under project **Springy Store μServices** [wiki page](https://github.com/mohamed-taman/Springy-Store-Microservices/wiki). each such stage will be a release so you can go back and forward between releases to see the differences and how adding things solve specific problems we face. |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +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: |
| 14 | + |
| 15 | +- The second stage I will introduce **database integration**, then in |
| 16 | +- The third stage I will introduce **Dockerization** of our services and **docker-compose**, and in |
| 17 | +- The fourth stage I will introduce **service discovery**, and so on. |
| 18 | + |
| 19 | +## Getting started |
| 20 | + |
| 21 | +The first stage aka (**Release v1.0**) is about creating and implementing a set of project Microservices. |
| 22 | + |
| 23 | +### Creating a Set of Cooperating Microservices |
| 24 | + |
| 25 | +The following topics are covered in this 1st stage (other stages topics will be documented in a project wiki): |
| 26 | + |
| 27 | +- Introducing the microservice landscape. |
| 28 | +- Generating skeleton microservices. |
| 29 | +- Adding RESTful APIs. |
| 30 | +- Adding a **product composite**, **product**, **recommendation**, and **review** microservices. |
| 31 | +- Adding error handling. |
| 32 | +- Testing the APIs manually. |
| 33 | +- Adding automated tests of microservices in isolation. |
| 34 | +- Adding semi-automated tests to a microservice landscape. |
| 35 | + |
| 36 | +### System Boundary - μServices Landscape |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +### Required software |
| 41 | + |
| 42 | +The following software pieces are initially required: |
| 43 | + |
| 44 | +1. **Git**: it can be downloaded and installed from https://git-scm.com/downloads. |
| 45 | + |
| 46 | +2. **Java 14**: it can be downloaded and installed from https://www.oracle.com/technetwork/java/javase/downloads/index.html. |
| 47 | + |
| 48 | +3. **curl**: this command-line tool for testing HTTP-based APIs can be downloaded and installed from https://curl.haxx.se/download.html. |
| 49 | + |
| 50 | +4. **jq**: This command-line JSON processor can be downloaded and installed from https://stedolan.github.io/jq/download/. |
| 51 | + |
| 52 | +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/. |
| 53 | + |
| 54 | + > For each future stage, I will list the newly required software. |
| 55 | +
|
| 56 | +Follow the installation guide for each software website and check your software versions from the command line to verify that they are installed correctly. |
| 57 | + |
| 58 | +## Using an IDE |
| 59 | + |
| 60 | +I recommend that you work with your Java code using an IDE that supports the development of Spring Boot applications such as Spring Tool Suite or IntelliJ IDEA Ultimate Edition. So you can use the Spring Boot Dashboard to run the services, run each microservice test case and many more. |
| 61 | + |
| 62 | +All that you want to do is just fire up your IDE **->** open or import the parent folder `springy-store-microservices` and everything will be ready for you. |
| 63 | + |
| 64 | +## Playing With Spring Store Project |
| 65 | + |
| 66 | +### Cloning It |
| 67 | + |
| 68 | +First open **git bash** command line, then simply you can clone the project under any of your favorite places as the following: |
| 69 | + |
| 70 | +```bash |
| 71 | +> git clone https://github.com/mohamed-taman/Springy-Store-Microservices.git |
| 72 | +``` |
| 73 | + |
| 74 | +### Build & Test Them In Isolation |
| 75 | + |
| 76 | +To build and run test cases for each service & shared modules in the project we need to do the following: |
| 77 | + |
| 78 | +#### First: Build & Install Shared Dependencies |
| 79 | + |
| 80 | +> This is done for the first time only or any new version of shared modules.. |
| 81 | +
|
| 82 | +To build and install `store-utils`, `store-api`, `store-chassis` libraries, from the root folder `springy-store-microservices` run the following commands: |
| 83 | + |
| 84 | +```bash |
| 85 | +mohamed.taman@DTLNV8 ~/springy-store-microservices |
| 86 | +λ ./setup.sh |
| 87 | +``` |
| 88 | + |
| 89 | +and you should expect output like this: |
| 90 | + |
| 91 | +```bash |
| 92 | +mohamed.taman@DTLNV8 ~/Springy Store Microservices |
| 93 | +λ ./setup.sh |
| 94 | + |
| 95 | +Installing all Springy store core shared modules |
| 96 | +................................................ |
| 97 | + |
| 98 | +1- Installing shared [Utilities] module... |
| 99 | +Done successfully. |
| 100 | + |
| 101 | +2- Installing shared [APIs] module... |
| 102 | +Done successfully. |
| 103 | + |
| 104 | +3- Installing [parent project] module... |
| 105 | +Done successfully. |
| 106 | + |
| 107 | +Wooohooo, building & installing all project modules are finished successfully. |
| 108 | +and the project is ready for the next step. :) |
| 109 | +``` |
| 110 | + |
| 111 | +#### Second: Build & Test Microservices |
| 112 | + |
| 113 | +Now it is time to build our **4 microservices** and run each service integration test in isolation by running the following commands: |
| 114 | + |
| 115 | +```bash |
| 116 | +mohamed.taman@DTLNV8 ~/springy-store-microservices |
| 117 | +λ cd store-chassis |
| 118 | +mohamed.taman@DTLNV8 ~/springy-store-microservices/store-chassis |
| 119 | +λ mvn clean verify |
| 120 | +``` |
| 121 | + |
| 122 | +All build commands and test suite for each microservice should run successfully and the final output should be like this: |
| 123 | + |
| 124 | +```bash |
| 125 | +[INFO] ------------------------------------------------------------------------ |
| 126 | +[INFO] Reactor Summary: |
| 127 | +[INFO] |
| 128 | +[INFO] Springy Store APIs 1.0-SNAPSHOT .................... SUCCESS [ 3.048 s] |
| 129 | +[INFO] Springy Store Utils 1.0-SNAPSHOT ................... SUCCESS [ 2.107 s] |
| 130 | +[INFO] Springy Store Chassis 0.0.1-SNAPSHOT ............... SUCCESS [ 0.865 s] |
| 131 | +[INFO] Product Composite Service 0.0.1-SNAPSHOT ........... SUCCESS [ 11.086 s] |
| 132 | +[INFO] Product Service 0.0.1-SNAPSHOT ..................... SUCCESS [ 9.795 s] |
| 133 | +[INFO] Review Service 0.0.1-SNAPSHOT ...................... SUCCESS [ 9.214 s] |
| 134 | +[INFO] Recommendation Service 0.0.1-SNAPSHOT .............. SUCCESS [ 9.288 s] |
| 135 | +[INFO] ------------------------------------------------------------------------ |
| 136 | +[INFO] BUILD SUCCESS |
| 137 | +[INFO] ------------------------------------------------------------------------ |
| 138 | +[INFO] Total time: 46.006 s |
| 139 | +[INFO] Finished at: 2020-04-01T17:07:52+02:00 |
| 140 | +[INFO] ------------------------------------------------------------------------ |
| 141 | +``` |
| 142 | + |
| 143 | +### Running Them |
| 144 | + |
| 145 | +Now it is time to run all of them, and it is very simple just run the following two commands: |
| 146 | + |
| 147 | +```bash |
| 148 | +mohamed.taman@DTLNV8 ~/springy-store-microservices/store-chassis |
| 149 | +λ cd .. |
| 150 | +mohamed.taman@DTLNV8 ~/springy-store-microservices |
| 151 | +λ ./run-em-all.sh |
| 152 | +``` |
| 153 | + |
| 154 | +All the services will run in parallel and their output will be printed to the console. |
| 155 | + |
| 156 | +### Testing Them All |
| 157 | + |
| 158 | +Now it is time to test all functionality of the application as one part. and to do so just run the following automation test script: |
| 159 | + |
| 160 | +```bash |
| 161 | +mohamed.taman@DTLNV8 ~/springy-store-microservices |
| 162 | +λ ./test-em-all.sh |
| 163 | +``` |
| 164 | + |
| 165 | +The result should be something like this: |
| 166 | + |
| 167 | +```bash |
| 168 | +Starting [Springy Store] full functionality testing.... |
| 169 | + |
| 170 | +HOST=localhost |
| 171 | +PORT=9080 |
| 172 | +Test OK (HTTP Code: 200) |
| 173 | +Test OK (actual value: 1) |
| 174 | +Test OK (actual value: 3) |
| 175 | +Test OK (actual value: 3) |
| 176 | +Test OK (HTTP Code: 404, {"httpStatus":"NOT_FOUND","message":"No product found for productId: 13","path":"/product-composite/13","time":"2020-04-01@14:51:48.812+0200"}) |
| 177 | +Test OK (HTTP Code: 200) |
| 178 | +Test OK (actual value: 113) |
| 179 | +Test OK (actual value: 0) |
| 180 | +Test OK (actual value: 3) |
| 181 | +Test OK (HTTP Code: 200) |
| 182 | +Test OK (actual value: 213) |
| 183 | +Test OK (actual value: 3) |
| 184 | +Test OK (actual value: 0) |
| 185 | +Test OK (HTTP Code: 422, {"httpStatus":"UNPROCESSABLE_ENTITY","message":"Invalid productId: -1","path":"/product-composite/-1","time":"2020-04-01@14:51:49.763+0200"}) |
| 186 | +Test OK (actual value: "Invalid productId: -1") |
| 187 | +Test OK (HTTP Code: 400, {"timestamp":"2020-04-01T12:51:49.965+0000","path":"/product-composite/invalidProductId","status":400,"error":"Bad Request","message":"Type mismatch."}) |
| 188 | +Test OK (actual value: "Type mismatch.") |
| 189 | +``` |
| 190 | + |
| 191 | +### Closing The Story |
| 192 | + |
| 193 | +And to close the story, we will need to shutdown Microservices manually service by service, hahaha just kidding, run the following script to shutdown them all: |
| 194 | + |
| 195 | +```bash |
| 196 | +mohamed.taman@DTLNV8 ~/springy-store-microservices |
| 197 | +λ ./stop-em-all.sh |
| 198 | +``` |
| 199 | + |
| 200 | + and the output should be as the following: |
| 201 | + |
| 202 | +```bash |
| 203 | +Stopping [Springy Store] μServices .... |
| 204 | +--------------------------------------- |
| 205 | + |
| 206 | +Stopping Microservice at port 9080 .... |
| 207 | +{"message":"Shutting down, bye..."} |
| 208 | +Microservice at port 9080 stopped successfully .... |
| 209 | + |
| 210 | +Stopping Microservice at port 9081 .... |
| 211 | +{"message":"Shutting down, bye..."} |
| 212 | +Microservice at port 9081 stopped successfully .... |
| 213 | + |
| 214 | +Stopping Microservice at port 9082 .... |
| 215 | +{"message":"Shutting down, bye..."} |
| 216 | +Microservice at port 9082 stopped successfully .... |
| 217 | + |
| 218 | +Stopping Microservice at port 9083 .... |
| 219 | +{"message":"Shutting down, bye..."} |
| 220 | +Microservice at port 9083 stopped successfully .... |
| 221 | +``` |
| 222 | + |
| 223 | +### The End |
| 224 | + |
| 225 | +Happy coding :) |
0 commit comments