├── .gitattributes ├── LICENSE ├── README.md ├── orderManagementApp ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── gl │ │ │ │ └── orderManagementApp │ │ │ │ ├── OrderManagementAppApplication.java │ │ │ │ ├── config │ │ │ │ ├── OrderConfig.java │ │ │ │ └── SwaggerConfig.java │ │ │ │ ├── controller │ │ │ │ └── UserRegistrationController.java │ │ │ │ ├── dto │ │ │ │ ├── Item.java │ │ │ │ └── SellerDto.java │ │ │ │ └── service │ │ │ │ ├── MyException.java │ │ │ │ ├── UserRegistrationService.java │ │ │ │ ├── UserRegistrationServiceImpl.java │ │ │ │ └── resilience4j │ │ │ │ └── UserRegistrationResilience4j.java │ │ └── resources │ │ │ └── application.yml │ └── test │ │ └── java │ │ └── com │ │ └── gl │ │ └── orderManagementApp │ │ └── OrderManagementAppApplicationTests.java └── ssl_server.jks └── registrationService ├── .gitignore ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── src ├── main │ ├── java │ │ └── com │ │ │ └── gl │ │ │ └── registrationService │ │ │ ├── RegistrationServiceApplication.java │ │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ └── RegistrationController.java │ │ │ ├── dto │ │ │ ├── Item.java │ │ │ └── SellerDto.java │ │ │ └── service │ │ │ ├── RegistrationRepository.java │ │ │ ├── RegistrationService.java │ │ │ └── RegistrationServiceImpl.java │ └── resources │ │ └── application.yml └── test │ └── java │ └── com │ └── gl │ └── registrationService │ └── RegistrationServiceApplicationTests.java └── ssl_server.jks /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Green Learner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # An introduction to resilience4j 2 | Resilience4j has many features like- Circuit breaker, bulkhead, rate limiter, retry. It also potential replacement candidate for Netflix hystris. To have the complete understanding watch video - 3 | 4 | https://youtu.be/Z_viIJSGXJw 5 | 6 | # Spring boot + resilience4j + Using annotations 7 | 8 | Below are the details about circuit breaker, bulkhead, retry and ratelimiter 9 | 10 | ## Circuit Breaker 11 | 12 | * Part 1 of 3 - https://youtu.be/Q1KlqAD8-6s 13 | 14 | * Part 2 of 3 - https://youtu.be/rZWV23nzGdk 15 | 16 | * Part 3 of 3 - https://youtu.be/VPvmP64VlMo 17 | 18 | ## Bulkhead 19 | 20 | Explained in video - 21 | 22 | * https://youtu.be/ib_cL26zOB8 23 | 24 | ## Retry 25 | 26 | Explained in video - 27 | 28 | * https://youtu.be/X7X2FXqPRaI 29 | 30 | ## Ratelimiter 31 | 32 | Explained in video - 33 | 34 | * https://youtu.be/GvcKYTZvrMM 35 | 36 | ## Application Monitoring 37 | 38 | I have explained micrometer, prometheus and Grafana. For full details watch below videos - 39 | 40 | * Part 1 of 2 - https://youtu.be/hOhHmnE9uXs 41 | 42 | * Part 2 of 2 - https://youtu.be/eVIeYE5lYMs 43 | 44 | -------------------------------------------------------------------------------- /orderManagementApp/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /orderManagementApp/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.7.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.8.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.gl' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.8' 10 | 11 | repositories { 12 | mavenCentral() 13 | maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } 14 | } 15 | 16 | ext { 17 | resilience4jVersion = '0.17.0' 18 | } 19 | 20 | dependencies { 21 | compile "io.github.resilience4j:resilience4j-spring-boot2:${resilience4jVersion}" 22 | compile('org.springframework.boot:spring-boot-starter-actuator') 23 | compile('org.springframework.boot:spring-boot-starter-aop') 24 | 25 | //aplication monitoring 26 | 27 | compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.2.1' 28 | 29 | 30 | //core lib 31 | implementation 'org.springframework.boot:spring-boot-starter-web' 32 | 33 | 34 | //swagger 35 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' 36 | implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' 37 | 38 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 39 | } 40 | 41 | -------------------------------------------------------------------------------- /orderManagementApp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/resilience4j/b68b624c97d0026cc2b4db6d8d35800cc5d61f37/orderManagementApp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /orderManagementApp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 27 00:34:25 IST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip 7 | -------------------------------------------------------------------------------- /orderManagementApp/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /orderManagementApp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /orderManagementApp/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'orderManagementApp' 2 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/OrderManagementAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OrderManagementAppApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OrderManagementAppApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/config/OrderConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.config; 2 | 3 | import org.springframework.boot.web.client.RestTemplateBuilder; 4 | import org.springframework.boot.web.client.RootUriTemplateHandler; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.client.RestTemplate; 8 | import org.springframework.web.util.UriTemplateHandler; 9 | 10 | /** 11 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 12 | */ 13 | 14 | @Configuration 15 | public class OrderConfig { 16 | 17 | private static final String baseUrl = "http://localhost:8086/registration"; 18 | 19 | @Bean 20 | RestTemplate restTemplate(RestTemplateBuilder builder) { 21 | UriTemplateHandler uriTemplateHandler = new RootUriTemplateHandler(baseUrl); 22 | return builder 23 | .uriTemplateHandler(uriTemplateHandler) 24 | .build(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.RequestHandlerSelectors; 6 | import springfox.documentation.service.ApiInfo; 7 | import springfox.documentation.service.Contact; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | import java.util.ArrayList; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerConfig { 17 | 18 | @Bean 19 | public Docket swagConfig(){ 20 | return new Docket(DocumentationType.SWAGGER_2).select() 21 | .apis(RequestHandlerSelectors.basePackage("com.gl")) 22 | .build() 23 | .apiInfo(getApiInfo()); 24 | } 25 | 26 | private ApiInfo getApiInfo() { 27 | return new ApiInfo("Order management application", 28 | "Documentation for Order management application", 29 | "1.0", 30 | "Terms of service for using Order management application", 31 | new Contact("Green Learner","https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA","greenlearner01@gmail.com"), 32 | "MIT Licence", 33 | "https://opensource.org/licenses/MIT", 34 | new ArrayList<>() 35 | ); 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/controller/UserRegistrationController.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.controller; 2 | 3 | import com.gl.orderManagementApp.dto.SellerDto; 4 | import com.gl.orderManagementApp.service.UserRegistrationService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 15 | */ 16 | 17 | @RestController 18 | public class UserRegistrationController { 19 | 20 | @Autowired 21 | private UserRegistrationService userRegistrationService; 22 | 23 | @PostMapping("/register/seller") 24 | public String registerAsSeller(@RequestBody SellerDto sellerDto) { 25 | return userRegistrationService.registerSeller(sellerDto); 26 | } 27 | 28 | @GetMapping("/sellerList") 29 | public List getSellersList() { 30 | return userRegistrationService.getSellersList(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/dto/Item.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.dto; 2 | 3 | public class Item { 4 | private long id; 5 | private String name; 6 | private String category; 7 | private double price;//per item 8 | 9 | public long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(long id) { 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public String getCategory() { 26 | return category; 27 | } 28 | 29 | public void setCategory(String category) { 30 | this.category = category; 31 | } 32 | 33 | public double getPrice() { 34 | return price; 35 | } 36 | 37 | public void setPrice(double price) { 38 | this.price = price; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Item{" + 44 | "id=" + id + 45 | ", name='" + name + '\'' + 46 | ", category='" + category + '\'' + 47 | ", price=" + price + 48 | '}'; 49 | } 50 | } -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/dto/SellerDto.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.dto; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 7 | */ 8 | public class SellerDto { 9 | 10 | private long id; 11 | 12 | private String firstName; 13 | 14 | private String lastName; 15 | 16 | private String emailId; 17 | 18 | private List itemsSold; 19 | 20 | public long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getFirstName() { 29 | return firstName; 30 | } 31 | 32 | public void setFirstName(String firstName) { 33 | this.firstName = firstName; 34 | } 35 | 36 | public String getLastName() { 37 | return lastName; 38 | } 39 | 40 | public void setLastName(String lastName) { 41 | this.lastName = lastName; 42 | } 43 | 44 | public String getEmailId() { 45 | return emailId; 46 | } 47 | 48 | public void setEmailId(String emailId) { 49 | this.emailId = emailId; 50 | } 51 | 52 | public List getItemsSold() { 53 | return itemsSold; 54 | } 55 | 56 | public void setItemsSold(List itemsSold) { 57 | this.itemsSold = itemsSold; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "SellerDto{" + 63 | "id=" + id + 64 | ", firstName='" + firstName + '\'' + 65 | ", lastName='" + lastName + '\'' + 66 | ", emailId='" + emailId + '\'' + 67 | ", itemsSold=" + itemsSold + 68 | '}'; 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/service/MyException.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.service; 2 | 3 | /** 4 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 5 | */ 6 | public class MyException extends Exception{ 7 | public MyException(String msg) { 8 | super(msg); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/service/UserRegistrationService.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.service; 2 | 3 | import com.gl.orderManagementApp.dto.SellerDto; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 9 | */ 10 | public interface UserRegistrationService { 11 | String registerSeller(SellerDto sellerDto); 12 | 13 | List getSellersList(); 14 | } 15 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/service/UserRegistrationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.service; 2 | 3 | import com.gl.orderManagementApp.dto.SellerDto; 4 | import com.gl.orderManagementApp.service.resilience4j.UserRegistrationResilience4j; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 13 | */ 14 | 15 | @Service 16 | public class UserRegistrationServiceImpl implements UserRegistrationService { 17 | 18 | Logger logger = LoggerFactory.getLogger(UserRegistrationServiceImpl.class); 19 | private UserRegistrationResilience4j userRegistrationResilience4j; 20 | 21 | 22 | public UserRegistrationServiceImpl(UserRegistrationResilience4j userRegistrationResilience4j) { 23 | this.userRegistrationResilience4j = userRegistrationResilience4j; 24 | } 25 | 26 | @Override 27 | public String registerSeller(SellerDto sellerDto) { 28 | 29 | String registerSeller = null; 30 | 31 | //for (int i = 0; i < 10000; i++) { 32 | long start = System.currentTimeMillis(); 33 | 34 | registerSeller = userRegistrationResilience4j.registerSeller(sellerDto); 35 | 36 | logger.info("add seller call returned in - {}", System.currentTimeMillis() - start); 37 | // } 38 | //registerSeller = userRegistrationResilience4j.registerSeller(sellerDto); 39 | return registerSeller; 40 | 41 | } 42 | 43 | @Override 44 | public List getSellersList() { 45 | return userRegistrationResilience4j.getSellersList(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/java/com/gl/orderManagementApp/service/resilience4j/UserRegistrationResilience4j.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp.service.resilience4j; 2 | 3 | import com.gl.orderManagementApp.dto.SellerDto; 4 | import io.github.resilience4j.bulkhead.annotation.Bulkhead; 5 | import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker; 6 | import io.github.resilience4j.ratelimiter.annotation.RateLimiter; 7 | import io.github.resilience4j.retry.annotation.Retry; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 18 | */ 19 | 20 | @Service 21 | public class UserRegistrationResilience4j { 22 | Logger logger = LoggerFactory.getLogger(UserRegistrationResilience4j.class); 23 | private RestTemplate restTemplate; 24 | 25 | public UserRegistrationResilience4j(RestTemplate restTemplate) { 26 | this.restTemplate = restTemplate; 27 | } 28 | 29 | 30 | @CircuitBreaker(name = "service1", fallbackMethod = "fallbackForRegisterSeller") 31 | @RateLimiter(name = "service1", fallbackMethod = "rateLimiterfallback") 32 | @Retry(name = "retryService1", fallbackMethod = "retryfallback") 33 | @Bulkhead(name = "bulkheadService1", fallbackMethod = "bulkHeadFallback") 34 | public String registerSeller(SellerDto sellerDto) { 35 | String response = restTemplate.postForObject("/addSeller", sellerDto, String.class); 36 | return response; 37 | } 38 | 39 | @CircuitBreaker(name = "service2", fallbackMethod = "fallbackForGetSeller") 40 | public List getSellersList() { 41 | logger.info("calling getSellerList()"); 42 | return restTemplate.getForObject("/sellersList", List.class); 43 | } 44 | public String rateLimiterfallback(SellerDto sellerDto, Throwable t) { 45 | logger.error("Inside rateLimiterfallback, cause - {}", t.toString()); 46 | return "Inside rateLimiterfallback method. Some error occurred while calling service for seller registration"; 47 | } 48 | public String bulkHeadFallback(SellerDto sellerDto, Throwable t) { 49 | logger.error("Inside bulkHeadFallback, cause - {}", t.toString()); 50 | return "Inside bulkHeadFallback method. Some error occurred while calling service for seller registration"; 51 | } 52 | public String retryfallback(SellerDto sellerDto, Throwable t) { 53 | logger.error("Inside retryfallback, cause - {}", t.toString()); 54 | return "Inside retryfallback method. Some error occurred while calling service for seller registration"; 55 | } 56 | public String fallbackForRegisterSeller(SellerDto sellerDto, Throwable t) { 57 | logger.error("Inside circuit breaker fallbackForRegisterSeller, cause - {}", t.toString()); 58 | return "Inside circuit breaker fallback method. Some error occurred while calling service for seller registration"; 59 | } 60 | 61 | public List fallbackForGetSeller(Throwable t) { 62 | logger.error("Inside fallbackForGetSeller, cause - {}", t.toString()); 63 | SellerDto sd = new SellerDto(); 64 | sd.setFirstName("john"); 65 | sd.setId(1111); 66 | sd.setEmailId("default"); 67 | List defaultList = new ArrayList<>(); 68 | defaultList.add(sd); 69 | return defaultList; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /orderManagementApp/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8085 3 | 4 | management.endpoints.web.exposure.include: '*' 5 | management.endpoint.health.show-details: always 6 | 7 | resilience4j.circuitbreaker: 8 | instances: 9 | service1: 10 | registerHealthIndicator: true 11 | ringBufferSizeInClosedState: 5 12 | ringBufferSizeInHalfOpenState: 3 13 | waitDurationInOpenState: 10s 14 | failureRateThreshold: 50 15 | recordExceptions: 16 | - org.springframework.web.client.HttpServerErrorException 17 | - java.io.IOException 18 | - java.util.concurrent.TimeoutException 19 | - org.springframework.web.client.ResourceAccessException 20 | ignoreExceptions: 21 | - com.gl.orderManagementApp.service.MyException 22 | service2: 23 | registerHealthIndicator: true 24 | ringBufferSizeInClosedState: 6 25 | ringBufferSizeInHalfOpenState: 4 26 | waitDurationInOpenState: 20s 27 | failureRateThreshold: 60 28 | 29 | resilience4j.ratelimiter: 30 | instances: 31 | service1: 32 | limitForPeriod: 10 33 | limitRefreshPeriod: 100000 34 | timeoutDuration: 1000ms 35 | 36 | resilience4j.retry: 37 | instances: 38 | retryService1: 39 | maxRetryAttempts: 5 40 | waitDuration: 10000 41 | 42 | resilience4j.bulkhead: 43 | instances: 44 | bulkheadService1: 45 | maxWaitDuration: 10ms 46 | maxConcurrentCall: 30 47 | 48 | resilience4j.thread-pool-bulkhead: 49 | instances: 50 | bulkheadService1: 51 | maxThreadPoolSize: 1 52 | coreThreadPoolSize: 1 53 | queueCapacity: 1 -------------------------------------------------------------------------------- /orderManagementApp/src/test/java/com/gl/orderManagementApp/OrderManagementAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.orderManagementApp; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderManagementAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /orderManagementApp/ssl_server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/resilience4j/b68b624c97d0026cc2b4db6d8d35800cc5d61f37/orderManagementApp/ssl_server.jks -------------------------------------------------------------------------------- /registrationService/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /registrationService/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.7.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.8.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.gl' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.8' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | 18 | //swagger 19 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' 20 | implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' 21 | 22 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 23 | } 24 | -------------------------------------------------------------------------------- /registrationService/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/resilience4j/b68b624c97d0026cc2b4db6d8d35800cc5d61f37/registrationService/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /registrationService/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /registrationService/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /registrationService/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /registrationService/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'registrationService' 2 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/RegistrationServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RegistrationServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RegistrationServiceApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.RequestHandlerSelectors; 6 | import springfox.documentation.service.ApiInfo; 7 | import springfox.documentation.service.Contact; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | import java.util.ArrayList; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerConfig { 17 | 18 | @Bean 19 | public Docket swagConfig(){ 20 | return new Docket(DocumentationType.SWAGGER_2).select() 21 | .apis(RequestHandlerSelectors.basePackage("com.gl")) 22 | .build() 23 | .apiInfo(getApiInfo()); 24 | } 25 | 26 | private ApiInfo getApiInfo() { 27 | return new ApiInfo("User Registration Service", 28 | "Documentation for User Registration Service", 29 | "1.0", 30 | "Terms of service for using User Registration Service", 31 | new Contact("Green Learner","https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA","greenlearner01@gmail.com"), 32 | "MIT Licence", 33 | "https://opensource.org/licenses/MIT", 34 | new ArrayList<>() 35 | ); 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/controller/RegistrationController.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.controller; 2 | 3 | import com.gl.registrationService.dto.SellerDto; 4 | import com.gl.registrationService.service.RegistrationService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 12 | */ 13 | 14 | @RestController 15 | @RequestMapping("/registration") 16 | public class RegistrationController { 17 | 18 | @Autowired 19 | private RegistrationService registrationService; 20 | 21 | @PostMapping("/addSeller") 22 | public String addSeller(@RequestBody SellerDto sellerDto){ 23 | return registrationService.addSeller(sellerDto); 24 | } 25 | 26 | @GetMapping("/sellersList") 27 | public List getSellersList() { 28 | return registrationService.getSellersList(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/dto/Item.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.dto; 2 | 3 | public class Item { 4 | private long id; 5 | private String name; 6 | private String category; 7 | private double price;//per item 8 | 9 | public long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(long id) { 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public String getCategory() { 26 | return category; 27 | } 28 | 29 | public void setCategory(String category) { 30 | this.category = category; 31 | } 32 | 33 | public double getPrice() { 34 | return price; 35 | } 36 | 37 | public void setPrice(double price) { 38 | this.price = price; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Item{" + 44 | "id=" + id + 45 | ", name='" + name + '\'' + 46 | ", category='" + category + '\'' + 47 | ", price=" + price + 48 | '}'; 49 | } 50 | } -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/dto/SellerDto.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.dto; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 7 | */ 8 | public class SellerDto { 9 | 10 | private long id; 11 | 12 | private String firstName; 13 | 14 | private String lastName; 15 | 16 | private String emailId; 17 | 18 | private List itemsSold; 19 | 20 | public long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getFirstName() { 29 | return firstName; 30 | } 31 | 32 | public void setFirstName(String firstName) { 33 | this.firstName = firstName; 34 | } 35 | 36 | public String getLastName() { 37 | return lastName; 38 | } 39 | 40 | public void setLastName(String lastName) { 41 | this.lastName = lastName; 42 | } 43 | 44 | public String getEmailId() { 45 | return emailId; 46 | } 47 | 48 | public void setEmailId(String emailId) { 49 | this.emailId = emailId; 50 | } 51 | 52 | public List getItemsSold() { 53 | return itemsSold; 54 | } 55 | 56 | public void setItemsSold(List itemsSold) { 57 | this.itemsSold = itemsSold; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "SellerDto{" + 63 | "id=" + id + 64 | ", firstName='" + firstName + '\'' + 65 | ", lastName='" + lastName + '\'' + 66 | ", emailId='" + emailId + '\'' + 67 | ", itemsSold=" + itemsSold + 68 | '}'; 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/service/RegistrationRepository.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.service; 2 | 3 | import com.gl.registrationService.dto.SellerDto; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 11 | */ 12 | 13 | @Repository 14 | public class RegistrationRepository { 15 | 16 | List sellerDtoList = new ArrayList<>(); 17 | 18 | public boolean addSeller(SellerDto sellerDto) { 19 | 20 | return sellerDtoList.add(sellerDto); 21 | } 22 | 23 | public List getSellerList() { 24 | return sellerDtoList; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/service/RegistrationService.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.service; 2 | 3 | import com.gl.registrationService.dto.SellerDto; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 9 | */ 10 | public interface RegistrationService { 11 | 12 | 13 | String addSeller(SellerDto sellerDto); 14 | 15 | List getSellersList(); 16 | } 17 | -------------------------------------------------------------------------------- /registrationService/src/main/java/com/gl/registrationService/service/RegistrationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService.service; 2 | 3 | import com.gl.registrationService.dto.SellerDto; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author - GreenLearner(https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA) 13 | */ 14 | 15 | @Service 16 | public class RegistrationServiceImpl implements RegistrationService { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(RegistrationServiceImpl.class); 19 | private RegistrationRepository registrationRepository; 20 | 21 | public RegistrationServiceImpl(RegistrationRepository registrationRepository) { 22 | this.registrationRepository = registrationRepository; 23 | } 24 | 25 | @Override 26 | public String addSeller(@RequestBody SellerDto sellerDto) { 27 | 28 | if (sellerDto.getEmailId() == null || sellerDto.getEmailId().isEmpty()) { 29 | logger.error("email id which is mandatory field is null/empty"); 30 | throw new RuntimeException("Seller mail id is not valid. Please enter valid Id"); 31 | } 32 | sellerDto.setId(getSellersList().size() + 1); 33 | boolean isSellerAdded = registrationRepository.addSeller(sellerDto); 34 | String message; 35 | if (isSellerAdded) { 36 | message = "Registration successful. Your registration id is - '" + sellerDto.getId() + "'\n Save it for future communication with us."; 37 | 38 | } else { 39 | message = "There was some problem in registering the seller. Please try after some time!!"; 40 | 41 | } 42 | logger.info("Add seller status - {} and message - {}", isSellerAdded, message); 43 | return message; 44 | } 45 | 46 | @Override 47 | public List getSellersList() { 48 | 49 | List sellerList = registrationRepository.getSellerList(); 50 | logger.info("fetching seller list. Total sellers - {}", sellerList.size()); 51 | return sellerList; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /registrationService/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8086 3 | -------------------------------------------------------------------------------- /registrationService/src/test/java/com/gl/registrationService/RegistrationServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.registrationService; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RegistrationServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /registrationService/ssl_server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/resilience4j/b68b624c97d0026cc2b4db6d8d35800cc5d61f37/registrationService/ssl_server.jks --------------------------------------------------------------------------------