├── .gitignore ├── README.md ├── airtel-store-service ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── barath │ │ │ └── airtel │ │ │ └── app │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ ├── EurekaConfiguration.java │ │ │ └── RouterConfiguration.java │ │ │ ├── entity │ │ │ └── Customer.java │ │ │ ├── handler │ │ │ └── CustomerHandler.java │ │ │ ├── repository │ │ │ └── CustomerRepository.java │ │ │ └── service │ │ │ └── CustomerService.java │ └── resources │ │ ├── application-eureka.yml │ │ └── application.yml │ └── test │ └── java │ └── com │ └── barath │ └── airtel │ └── app │ └── ApplicationTests.java ├── config-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── barath │ │ │ └── app │ │ │ └── ConfigServerApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── barath │ └── app │ └── ConfigServerApplicationTests.java ├── docker-compose.yml ├── eureka-server ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── Dockerfile.build ├── manifest.yml ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── barath │ │ │ └── app │ │ │ └── EurekaServerApplication.java │ └── resources │ │ ├── application.yml │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── barath │ └── app │ └── EurekaServerApplicationTests.java ├── images ├── eureka_registration_view.png ├── spring_cloud_gateway.png ├── spring_cloud_gateway_header.png └── spring_cloud_gateway_param.png ├── jio-store-service ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── barath │ │ │ └── jio │ │ │ └── app │ │ │ ├── Application.java │ │ │ ├── configuration │ │ │ ├── EurekaConfiguration.java │ │ │ └── RouterConfiguration.java │ │ │ ├── entity │ │ │ └── Customer.java │ │ │ ├── handler │ │ │ └── CustomerHandler.java │ │ │ ├── repository │ │ │ └── CustomerRepository.java │ │ │ └── service │ │ │ └── CustomerService.java │ └── resources │ │ ├── application-eureka.yml │ │ └── application.yml │ └── test │ └── java │ └── com │ └── barath │ └── jio │ └── app │ └── JioStoreServiceApplicationTests.java ├── k8s └── k8s.yaml ├── pom.xml ├── spring-cloud-gateway ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── barath │ │ │ └── gateway │ │ │ └── app │ │ │ ├── EurekaConfiguration.java │ │ │ └── GatewayApplication.java │ └── resources │ │ ├── application-eureka.yml │ │ ├── application-header.yml │ │ ├── application-path.yml │ │ ├── application-query.yml │ │ └── application.yml │ └── test │ └── java │ └── com │ └── barath │ └── gateway │ └── app │ └── SpringCloudGatewayApplicationTests.java └── vodaphone-store-service ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── barath │ │ └── vodaphone │ │ └── app │ │ ├── Application.java │ │ ├── configuration │ │ ├── EurekaConfiguration.java │ │ └── RouterConfiguration.java │ │ ├── entity │ │ └── Customer.java │ │ ├── handler │ │ └── CustomerHandler.java │ │ ├── repository │ │ └── CustomerRepository.java │ │ └── service │ │ └── CustomerService.java └── resources │ ├── application-eureka.yml │ └── application.yml └── test └── java └── com └── barath └── vodaphone └── app └── ApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | .vscode/* 25 | .vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-cloud-gateway-routing 2 | This project demonstrates the usage of API gateway between microservices using spring cloud gateway. 3 | 4 | 5 | ## what is spring cloud gateway ? 6 | 7 |

Spring Cloud Gateway is an intelligent and programmable router based on Project Reactor.

8 | 9 | 10 | ![spring cloud gateway](images/spring_cloud_gateway.png) 11 | 12 | 13 | #### Compatability Matrix 14 | 15 | choose the branch based on below maintained versions. 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
Branch/VersionSpring BootSpring Cloud
master2.1.5.RELEASEGreenwich.SR1
v2.1.32.1.3.RELEASEGreenwich.RELEASE
34 | 35 | #### Projects 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
NamePortDescription
spring-cloud-gateway9500spring cloud gateway router
jio-store-service9501jio microservice
airtel-store-service9502airtel microservice
vodaphone-store-service9503vodaphone microservice
config-server8888spring cloud config server
eureka-server8761eureka-server
77 | 78 | #### Eureka Server Registration (Optional) 79 | 80 | By default eureka is disabled. 81 | 82 | ```yaml 83 | eureka: 84 | client: 85 | enabled: false 86 | ``` 87 | 88 | To enable eureka, set below property in all the microservices and restart. 89 | 90 | ```yaml 91 | spring: 92 | profiles: 93 | active: eureka 94 | ``` 95 | 96 | 97 | #### How to build and run ? 98 | 99 | * Download/Clone the repository : 100 | 101 | ``` 102 | $ git clone https://github.com/BarathArivazhagan/spring-cloud-gateway-routing.git 103 | $ cd spring-cloud-gateway-routing 104 | $ ./mvnw clean install 105 | ``` 106 | 107 | * To run the application : 108 | 109 | ``` 110 | $ docker-compose up 111 | ``` 112 | 113 | #### How to test the application ? 114 | 115 | Use gateway routes to route to respective microservices. 116 | 117 | spring cloud gateway route definition : 118 | 119 | ``` 120 | spring: 121 | cloud: 122 | gateway: 123 | routes: 124 | - id: jio-service 125 | uri: http://localhost:9501 126 | predicates: 127 | - Path= /jio/* 128 | filters: 129 | - StripPrefix=1 # required to strip the prefix made to the request . Ex /jio/customers request will go to jio service as /customers 130 | - id: airtel-service 131 | uri: http://localhost:9502 132 | predicates: 133 | - Path= /airtel/* 134 | filters: 135 | - StripPrefix=1 136 | - id: vodaphone-service 137 | uri: http://localhost:9503 138 | predicates: 139 | - Path= /vodaphone/* 140 | filters: 141 | - StripPrefix=1 142 | ``` 143 | 144 | ``` 145 | $ curl http://localhost:9500/jio/customers 146 | 147 | [ 148 | { 149 | "customerName": "barath-jio", 150 | "customerAge": 25, 151 | "customerGender": "MALE" 152 | } 153 | ] 154 | 155 | $ curl http://localhost:9500/airtel/customers 156 | 157 | [ 158 | { 159 | "customerName": "barath-airtel", 160 | "customerAge": 25, 161 | "customerGender": "MALE" 162 | } 163 | ] 164 | 165 | $ curl http://localhost:9500/vodaphone/customers 166 | 167 | [ 168 | { 169 | "customerName": "barath-vodaphone", 170 | "customerAge": 25, 171 | "customerGender": "MALE" 172 | } 173 | ] 174 | ``` 175 | 176 | 177 | #### Header based routing strategy 178 | 179 | ![spring cloud gateway](images/spring_cloud_gateway_header.png) 180 | 181 | Enable SPRING_PROFILES_ACTIVE=header to test header based routing strategy 182 | 183 | 184 | #### Query param based routing strategy 185 | 186 | ![spring cloud gateway](images/spring_cloud_gateway_param.png) 187 | 188 | Enable SPRING_PROFILES_ACTIVE=query to test query param based routing strategy 189 | 190 | #### Eureka Registration View 191 | 192 | ![eureka_registration_view](images/eureka_registration_view.png) 193 | 194 | 195 | 196 | #### How to rebuild the project after the changes? 197 | 198 | ``` 199 | docker-compose build 200 | ``` 201 | 202 | 203 | 204 | ## References 205 | 206 | * [spriing-cloud](http://projects.spring.io/spring-cloud/) 207 | 208 | * [spring-cloud-gateway](https://cloud.spring.io/spring-cloud-gateway/) 209 | 210 | 211 | -------------------------------------------------------------------------------- /airtel-store-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /airtel-store-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/airtel-store-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /airtel-store-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /airtel-store-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | VOLUME /tmp 5 | ADD target/airtel-store-service-*.jar app.jar 6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] 7 | -------------------------------------------------------------------------------- /airtel-store-service/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /airtel-store-service/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /airtel-store-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | airtel-store-service 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | airtel-store-service 12 | airtel-store-service microservice 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-jpa 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-webflux 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-devtools 45 | runtime 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-starter-netflix-eureka-client 50 | 51 | 52 | org.hsqldb 53 | hsqldb 54 | runtime 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-test 59 | test 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.cloud 75 | spring-cloud-dependencies 76 | ${spring-cloud.version} 77 | pom 78 | import 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/Application.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/configuration/EurekaConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.configuration; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | @Profile("eureka") 8 | @Configuration 9 | @EnableDiscoveryClient 10 | public class EurekaConfiguration { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/configuration/RouterConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.configuration; 2 | 3 | import com.barath.airtel.app.handler.CustomerHandler; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.RouterFunctions; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | 11 | import static org.springframework.web.reactive.function.server.RequestPredicates.GET; 12 | import static org.springframework.web.reactive.function.server.RequestPredicates.POST; 13 | import static org.springframework.web.reactive.function.server.RequestPredicates.accept; 14 | 15 | 16 | /** 17 | * @author barath 18 | */ 19 | @Configuration 20 | public class RouterConfiguration { 21 | 22 | private CustomerHandler customerHandler; 23 | 24 | public RouterConfiguration(CustomerHandler customerHandler){ 25 | this.customerHandler=customerHandler; 26 | } 27 | 28 | @Bean 29 | public RouterFunction routes(){ 30 | 31 | return RouterFunctions 32 | .route(POST("/customer") 33 | .and(accept(MediaType.APPLICATION_JSON_UTF8)),customerHandler::addCustomer) 34 | .andRoute(GET("/customer/{customerName}"),customerHandler::getCustomer) 35 | .andRoute(GET("/customers"),customerHandler::getCustomers); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import javax.persistence.*; 7 | 8 | /** 9 | * @author barath 10 | */ 11 | @Entity 12 | @Table(name = "CUSTOMER") 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | public class Customer { 15 | 16 | @Id 17 | @GeneratedValue 18 | @JsonIgnore 19 | @Column(name = "CUSTOMER_ID") 20 | private Long customerId; 21 | 22 | @Column(name = "CUSTOMER_NAME",nullable = false,length = 100) 23 | private String customerName; 24 | 25 | @Column(name = "CUSTOMER_AGE",nullable = false,length = 3) 26 | private int customerAge; 27 | 28 | 29 | @Enumerated(EnumType.STRING) 30 | @Column(name = "CUSTOMER_GENDER",length = 10) 31 | private CustomerGender customerGender; 32 | 33 | public enum CustomerGender{ 34 | MALE,FEMALE 35 | } 36 | 37 | public Customer(Long customerId, String customerName, int customerAge, CustomerGender customerGender) { 38 | this.customerId = customerId; 39 | this.customerName = customerName; 40 | this.customerAge = customerAge; 41 | this.customerGender = customerGender; 42 | } 43 | 44 | public Customer(String customerName, int customerAge, CustomerGender customerGender) { 45 | this.customerName = customerName; 46 | this.customerAge = customerAge; 47 | this.customerGender = customerGender; 48 | } 49 | 50 | protected Customer() { 51 | } 52 | 53 | public Long getCustomerId() { 54 | return customerId; 55 | } 56 | 57 | public void setCustomerId(Long customerId) { 58 | this.customerId = customerId; 59 | } 60 | 61 | public String getCustomerName() { 62 | return customerName; 63 | } 64 | 65 | public void setCustomerName(String customerName) { 66 | this.customerName = customerName; 67 | } 68 | 69 | public int getCustomerAge() { 70 | return customerAge; 71 | } 72 | 73 | public void setCustomerAge(int customerAge) { 74 | this.customerAge = customerAge; 75 | } 76 | 77 | public CustomerGender getCustomerGender() { 78 | return customerGender; 79 | } 80 | 81 | public void setCustomerGender(CustomerGender customerGender) { 82 | this.customerGender = customerGender; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Customer{" + 88 | "customerId=" + customerId + 89 | ", customerName='" + customerName + '\'' + 90 | ", customerAge=" + customerAge + 91 | ", customerGender=" + customerGender + 92 | '}'; 93 | } 94 | 95 | @Override 96 | public boolean equals(Object o) { 97 | if (this == o) return true; 98 | if (o == null || getClass() != o.getClass()) return false; 99 | 100 | Customer customer = (Customer) o; 101 | 102 | if (customerAge != customer.customerAge) return false; 103 | if (customerId != null ? !customerId.equals(customer.customerId) : customer.customerId != null) return false; 104 | if (customerName != null ? !customerName.equals(customer.customerName) : customer.customerName != null) 105 | return false; 106 | return customerGender == customer.customerGender; 107 | } 108 | 109 | @Override 110 | public int hashCode() { 111 | int result = customerId != null ? customerId.hashCode() : 0; 112 | result = 31 * result + (customerName != null ? customerName.hashCode() : 0); 113 | result = 31 * result + customerAge; 114 | result = 31 * result + (customerGender != null ? customerGender.hashCode() : 0); 115 | return result; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/handler/CustomerHandler.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.handler; 2 | 3 | import java.lang.invoke.MethodHandles; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.reactive.function.server.ServerRequest; 10 | import org.springframework.web.reactive.function.server.ServerResponse; 11 | 12 | import com.barath.airtel.app.entity.Customer; 13 | import com.barath.airtel.app.service.CustomerService; 14 | 15 | import reactor.core.publisher.Mono; 16 | 17 | /** 18 | * @author barath 19 | */ 20 | @Component 21 | public class CustomerHandler { 22 | 23 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 24 | 25 | private CustomerService customerService; 26 | 27 | public CustomerHandler(CustomerService customerService) { 28 | this.customerService=customerService; 29 | } 30 | 31 | public Mono addCustomer(ServerRequest serverRequest){ 32 | 33 | return ServerResponse 34 | .ok() 35 | .contentType(MediaType.APPLICATION_JSON_UTF8) 36 | .body(customerService.addCustomer(serverRequest.bodyToMono(Customer.class)),Customer.class) 37 | .log(); 38 | } 39 | 40 | public Mono getCustomer(ServerRequest serverRequest){ 41 | 42 | return ServerResponse 43 | .ok() 44 | .contentType(MediaType.APPLICATION_JSON_UTF8) 45 | .body(customerService.getCustomer(serverRequest.pathVariable("customerName")),Customer.class) 46 | .log(); 47 | } 48 | 49 | public Mono getCustomers(ServerRequest serverRequest){ 50 | 51 | return ServerResponse 52 | .ok() 53 | .contentType(MediaType.APPLICATION_JSON_UTF8) 54 | .body(customerService.getCustomers(),Customer.class) 55 | .log(); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.repository; 2 | 3 | import com.barath.airtel.app.entity.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author barath 8 | */ 9 | public interface CustomerRepository extends JpaRepository { 10 | 11 | Customer findByCustomerName(String customerName); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/java/com/barath/airtel/app/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app.service; 2 | 3 | import java.lang.invoke.MethodHandles; 4 | import java.util.Arrays; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.stereotype.Service; 11 | 12 | import com.barath.airtel.app.entity.Customer; 13 | import com.barath.airtel.app.repository.CustomerRepository; 14 | 15 | import reactor.core.publisher.Flux; 16 | import reactor.core.publisher.Mono; 17 | 18 | /** 19 | * @author barath 20 | */ 21 | @Service 22 | public class CustomerService { 23 | 24 | private final CustomerRepository customerRepository; 25 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 26 | 27 | public CustomerService(CustomerRepository customerRepository) { 28 | this.customerRepository = customerRepository; 29 | } 30 | 31 | public Mono addCustomer(Mono customerMono){ 32 | 33 | return customerMono 34 | .doOnNext(customerRepository::save).doOnError( error -> { 35 | logger.error("error in creating a customer {}",error.getMessage()); 36 | }); 37 | } 38 | 39 | public Mono getCustomer(String customerName){ 40 | 41 | return Mono.just(customerRepository.findByCustomerName(customerName)); 42 | } 43 | 44 | public Flux getCustomers(){ 45 | 46 | return Flux.fromIterable(customerRepository.findAll()).log(); 47 | } 48 | 49 | /** 50 | * pre load customers for testing for in memory DB 51 | */ 52 | 53 | @PostConstruct 54 | public void init(){ 55 | 56 | customerRepository.saveAll(Arrays.asList(new Customer("barath-airtel", 30, Customer.CustomerGender.MALE))); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | enabled: true 4 | register-with-eureka: true 5 | fetch-registry: true 6 | service-url: 7 | default-zone: http://localhost:8761/eureka 8 | -------------------------------------------------------------------------------- /airtel-store-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 9502 4 | 5 | 6 | 7 | spring: 8 | application: 9 | name: airtel-store-service 10 | jpa: 11 | show-sql: true 12 | hibernate: 13 | ddl-auto: create 14 | 15 | # disable eureka by default 16 | 17 | eureka: 18 | client: 19 | enabled: false -------------------------------------------------------------------------------- /airtel-store-service/src/test/java/com/barath/airtel/app/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.airtel.app; 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 ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /config-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /config-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/config-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /config-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /config-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | VOLUME /tmp 5 | ADD target/config-server-*.jar app.jar 6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /config-server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /config-server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /config-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | config-server 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | config-server 12 | config-server service for configuration management 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-webflux 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-config-server 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-devtools 41 | runtime 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | io.projectreactor 50 | reactor-test 51 | test 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.cloud 59 | spring-cloud-dependencies 60 | ${spring-cloud.version} 61 | pom 62 | import 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-maven-plugin 72 | 73 | 74 | 75 | 76 | 77 | 78 | spring-milestones 79 | Spring Milestones 80 | https://repo.spring.io/milestone 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /config-server/src/main/java/com/barath/app/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.barath.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringBootApplication 8 | @EnableConfigServer 9 | public class ConfigServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 8888 4 | 5 | spring: 6 | application: 7 | name: config-server 8 | cloud: 9 | config: 10 | server: 11 | git: 12 | uri: https://github.com/BarathArivazhagan/spring-cloud-gateway-routing.git/config-properties 13 | 14 | 15 | -------------------------------------------------------------------------------- /config-server/src/test/java/com/barath/app/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.app; 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 ConfigServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | eureka-server: 4 | build: ./eureka-server 5 | image: barathece91/eureka-server-k8s 6 | ports: 7 | - "8761:8761" 8 | config-server: 9 | build: ./config-server 10 | image: barathece91/config-server-k8s 11 | ports: 12 | - "8888:8888" 13 | jio-microservice: 14 | build: ./jio-store-service 15 | image: barathece91/jio-store-service-k8s 16 | ports: 17 | - "9501:9501" 18 | airtel-microservice: 19 | build: ./airtel-store-service 20 | image: barathece91/airtel-store-service-k8s 21 | ports: 22 | - "9502:9502" 23 | vodaphone-microservice: 24 | build: ./vodaphone-store-service 25 | image: barathece91/vodaphone-store-service-k8s 26 | ports: 27 | - "9503:9503" 28 | spring-cloud-gateway-service: 29 | build: ./spring-cloud-gateway 30 | image: barathece91/gateway-service-k8s 31 | ports: 32 | - "9500:9500" 33 | depends_on: 34 | - jio-microservice 35 | - airtel-microservice 36 | - vodaphone-microservice 37 | environment: 38 | SPRING_PROFILES_ACTIVE: path 39 | SPRING_CLOUD_GATEWAY_ROUTES[0]_URI: http://jio-microservice:9501 40 | SPRING_CLOUD_GATEWAY_ROUTES[0]_ID: jio-service 41 | SPRING_CLOUD_GATEWAY_ROUTES[0]_PREDICATES[0]: Path= /jio/* 42 | SPRING_CLOUD_GATEWAY_ROUTES[0]_FILTERS[0]: StripPrefix=1 43 | SPRING_CLOUD_GATEWAY_ROUTES[1]_URI: http://airtel-microservice:9502 44 | SPRING_CLOUD_GATEWAY_ROUTES[1]_ID: airtel-service 45 | SPRING_CLOUD_GATEWAY_ROUTES[1]_PREDICATES[0]: Path= /airtel/* 46 | SPRING_CLOUD_GATEWAY_ROUTES[1]_FILTERS[0]: StripPrefix=1 47 | SPRING_CLOUD_GATEWAY_ROUTES[2]_URI: http://vodaphone-microservice:9503 48 | SPRING_CLOUD_GATEWAY_ROUTES[2]_ID: vodaphone-service 49 | SPRING_CLOUD_GATEWAY_ROUTES[2]_PREDICATES[0]: Path= /vodaphone/* 50 | SPRING_CLOUD_GATEWAY_ROUTES[2]_FILTERS[0]: StripPrefix=1 -------------------------------------------------------------------------------- /eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /eureka-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | ADD target/eureka-server-*.jar app.jar 5 | ENTRYPOINT ["java","-jar","app.jar"] 6 | 7 | -------------------------------------------------------------------------------- /eureka-server/Dockerfile.build: -------------------------------------------------------------------------------- 1 | 2 | # Builder stage 3 | FROM maven:3.5-jdk-8 as builder 4 | WORKDIR /opt 5 | COPY . /opt 6 | RUN mvn clean install 7 | 8 | 9 | # Final stage 10 | 11 | FROM openjdk:8-jdk-alpine as final 12 | # best practice is not to use root user 13 | RUN adduser -D demo 14 | USER demo 15 | COPY --from=builder /opt/target/eureka-server-*.jar app.jar 16 | ENTRYPOINT ["java","-jar","app.jar"] 17 | 18 | -------------------------------------------------------------------------------- /eureka-server/manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: eureka-server 4 | memory: 1024M 5 | buildpack: java_buildpack 6 | path: target/eureka-server-2.0.3.RELEASE.jar 7 | services: 8 | - config-client 9 | env: 10 | SPRING_PROFILES_ACTIVE: pcfdev 11 | #SPRING_PROFILES_ACTIVE: pcf -------------------------------------------------------------------------------- /eureka-server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /eureka-server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | eureka-server 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | eureka-server 12 | eureka-server for service registration 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-eureka-server 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-config 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-devtools 42 | runtime 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-dependencies 56 | ${spring-cloud.version} 57 | pom 58 | import 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 69 | 70 | 71 | 72 | 73 | spring-milestones 74 | Spring Milestones 75 | https://repo.spring.io/milestone 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /eureka-server/src/main/java/com/barath/app/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.barath.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | instance: 3 | hostname: localhost 4 | prefer-ip-address: true 5 | client: 6 | register-with-eureka: false 7 | fetch-registry: false 8 | serviceUrl: 9 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /eureka-server/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eureka-server 6 | 7 | 8 | -------------------------------------------------------------------------------- /eureka-server/src/test/java/com/barath/app/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.app; 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 EurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /images/eureka_registration_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/images/eureka_registration_view.png -------------------------------------------------------------------------------- /images/spring_cloud_gateway.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/images/spring_cloud_gateway.png -------------------------------------------------------------------------------- /images/spring_cloud_gateway_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/images/spring_cloud_gateway_header.png -------------------------------------------------------------------------------- /images/spring_cloud_gateway_param.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/images/spring_cloud_gateway_param.png -------------------------------------------------------------------------------- /jio-store-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /jio-store-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/jio-store-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /jio-store-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /jio-store-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | VOLUME /tmp 5 | ADD target/jio-store-service-*.jar app.jar 6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /jio-store-service/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /jio-store-service/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /jio-store-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | jio-store-service 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | jio-store-service 12 | jio-store-service microservice 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-jpa 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-webflux 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-devtools 44 | runtime 45 | 46 | 47 | org.hsqldb 48 | hsqldb 49 | runtime 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-test 54 | test 55 | 56 | 57 | org.springframework.cloud 58 | spring-cloud-starter-netflix-eureka-client 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework.cloud 74 | spring-cloud-dependencies 75 | ${spring-cloud.version} 76 | pom 77 | import 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/Application.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/configuration/EurekaConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.configuration; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | @Profile("eureka") 8 | @Configuration 9 | @EnableDiscoveryClient 10 | public class EurekaConfiguration { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/configuration/RouterConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.configuration; 2 | 3 | import static org.springframework.web.reactive.function.server.RequestPredicates.GET; 4 | import static org.springframework.web.reactive.function.server.RequestPredicates.POST; 5 | import static org.springframework.web.reactive.function.server.RequestPredicates.accept; 6 | 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.web.reactive.function.server.RouterFunction; 11 | import org.springframework.web.reactive.function.server.RouterFunctions; 12 | import org.springframework.web.reactive.function.server.ServerResponse; 13 | 14 | import com.barath.jio.app.handler.CustomerHandler; 15 | 16 | 17 | /** 18 | * @author barath 19 | */ 20 | @Configuration 21 | public class RouterConfiguration { 22 | 23 | private CustomerHandler customerHandler; 24 | 25 | public RouterConfiguration(CustomerHandler customerHandler){ 26 | this.customerHandler=customerHandler; 27 | } 28 | 29 | @Bean 30 | public RouterFunction routes(){ 31 | 32 | return RouterFunctions 33 | .route(POST("/customer/add") 34 | .and(accept(MediaType.APPLICATION_JSON_UTF8)),customerHandler::addCustomer) 35 | .andRoute(GET("/customer/get/{customerName}"),customerHandler::getCustomer) 36 | .andRoute(GET("/customers"),customerHandler::getCustomers); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import javax.persistence.*; 7 | 8 | /** 9 | * @author barath 10 | */ 11 | @Entity 12 | @Table(name = "CUSTOMER") 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | public class Customer { 15 | 16 | @Id 17 | @GeneratedValue 18 | @JsonIgnore 19 | @Column(name = "CUSTOMER_ID") 20 | private Long customerId; 21 | 22 | @Column(name = "CUSTOMER_NAME",nullable = false,length = 100) 23 | private String customerName; 24 | 25 | @Column(name = "CUSTOMER_AGE",nullable = false,length = 3) 26 | private int customerAge; 27 | 28 | 29 | @Enumerated(EnumType.STRING) 30 | @Column(name = "CUSTOMER_GENDER",length = 10) 31 | private CustomerGender customerGender; 32 | 33 | public enum CustomerGender{ 34 | MALE,FEMALE 35 | } 36 | 37 | public Customer(Long customerId, String customerName, int customerAge, CustomerGender customerGender) { 38 | this.customerId = customerId; 39 | this.customerName = customerName; 40 | this.customerAge = customerAge; 41 | this.customerGender = customerGender; 42 | } 43 | 44 | public Customer(String customerName, int customerAge, CustomerGender customerGender) { 45 | this.customerName = customerName; 46 | this.customerAge = customerAge; 47 | this.customerGender = customerGender; 48 | } 49 | 50 | protected Customer() { 51 | } 52 | 53 | public Long getCustomerId() { 54 | return customerId; 55 | } 56 | 57 | public void setCustomerId(Long customerId) { 58 | this.customerId = customerId; 59 | } 60 | 61 | public String getCustomerName() { 62 | return customerName; 63 | } 64 | 65 | public void setCustomerName(String customerName) { 66 | this.customerName = customerName; 67 | } 68 | 69 | public int getCustomerAge() { 70 | return customerAge; 71 | } 72 | 73 | public void setCustomerAge(int customerAge) { 74 | this.customerAge = customerAge; 75 | } 76 | 77 | public CustomerGender getCustomerGender() { 78 | return customerGender; 79 | } 80 | 81 | public void setCustomerGender(CustomerGender customerGender) { 82 | this.customerGender = customerGender; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Customer{" + 88 | "customerId=" + customerId + 89 | ", customerName='" + customerName + '\'' + 90 | ", customerAge=" + customerAge + 91 | ", customerGender=" + customerGender + 92 | '}'; 93 | } 94 | 95 | @Override 96 | public boolean equals(Object o) { 97 | if (this == o) return true; 98 | if (o == null || getClass() != o.getClass()) return false; 99 | 100 | Customer customer = (Customer) o; 101 | 102 | if (customerAge != customer.customerAge) return false; 103 | if (customerId != null ? !customerId.equals(customer.customerId) : customer.customerId != null) return false; 104 | if (customerName != null ? !customerName.equals(customer.customerName) : customer.customerName != null) 105 | return false; 106 | return customerGender == customer.customerGender; 107 | } 108 | 109 | @Override 110 | public int hashCode() { 111 | int result = customerId != null ? customerId.hashCode() : 0; 112 | result = 31 * result + (customerName != null ? customerName.hashCode() : 0); 113 | result = 31 * result + customerAge; 114 | result = 31 * result + (customerGender != null ? customerGender.hashCode() : 0); 115 | return result; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/handler/CustomerHandler.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.handler; 2 | 3 | import com.barath.jio.app.entity.Customer; 4 | import com.barath.jio.app.service.CustomerService; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.reactive.function.server.ServerRequest; 10 | import org.springframework.web.reactive.function.server.ServerResponse; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.lang.invoke.MethodHandles; 14 | 15 | /** 16 | * Created by barath on 03/03/18. 17 | */ 18 | 19 | @Component 20 | public class CustomerHandler { 21 | 22 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 23 | 24 | private CustomerService customerService; 25 | 26 | public CustomerHandler(CustomerService customerService) { 27 | this.customerService=customerService; 28 | } 29 | 30 | public Mono addCustomer(ServerRequest serverRequest){ 31 | 32 | return ServerResponse 33 | .ok() 34 | .contentType(MediaType.APPLICATION_JSON_UTF8) 35 | .body(customerService.addCustomer(serverRequest.bodyToMono(Customer.class)),Customer.class) 36 | .log(); 37 | } 38 | 39 | public Mono getCustomer(ServerRequest serverRequest){ 40 | 41 | return ServerResponse 42 | .ok() 43 | .contentType(MediaType.APPLICATION_JSON_UTF8) 44 | .body(customerService.getCustomer(serverRequest.pathVariable("customerName")),Customer.class) 45 | .log(); 46 | } 47 | 48 | public Mono getCustomers(ServerRequest serverRequest){ 49 | 50 | return ServerResponse 51 | .ok() 52 | .contentType(MediaType.APPLICATION_JSON_UTF8) 53 | .body(customerService.getCustomers(),Customer.class) 54 | .log(); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.repository; 2 | 3 | import com.barath.jio.app.entity.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * Created by barath on 03/03/18. 8 | */ 9 | public interface CustomerRepository extends JpaRepository { 10 | 11 | Customer findByCustomerName(String customerName); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /jio-store-service/src/main/java/com/barath/jio/app/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app.service; 2 | 3 | import java.lang.invoke.MethodHandles; 4 | import java.util.Arrays; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.stereotype.Service; 11 | 12 | import com.barath.jio.app.entity.Customer; 13 | import com.barath.jio.app.repository.CustomerRepository; 14 | 15 | import reactor.core.publisher.Flux; 16 | import reactor.core.publisher.Mono; 17 | 18 | /** 19 | * @author barath 20 | */ 21 | @Service 22 | public class CustomerService { 23 | 24 | private CustomerRepository customerRepository; 25 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 26 | 27 | public CustomerService(CustomerRepository customerRepository) { 28 | this.customerRepository = customerRepository; 29 | } 30 | 31 | public Mono addCustomer(Mono customerMono){ 32 | 33 | return customerMono 34 | .doOnNext(customerRepository::save).doOnError( error -> { 35 | logger.error("error in creating a customer {}",error.getMessage()); 36 | }); 37 | } 38 | 39 | public Mono getCustomer(String customerName){ 40 | 41 | return Mono.just(customerRepository.findByCustomerName(customerName)); 42 | } 43 | 44 | public Flux getCustomers(){ 45 | 46 | return Flux.fromIterable(customerRepository.findAll()).log(); 47 | } 48 | 49 | /** 50 | * pre load customers for testing for in memory DB 51 | */ 52 | 53 | @PostConstruct 54 | public void init(){ 55 | 56 | customerRepository.saveAll(Arrays.asList(new Customer("barath-jio", 25, Customer.CustomerGender.MALE))); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /jio-store-service/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | enabled: true 4 | register-with-eureka: true 5 | fetch-registry: true 6 | service-url: 7 | default-zone: http://localhost:8761/eureka 8 | -------------------------------------------------------------------------------- /jio-store-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9501 3 | 4 | spring: 5 | application: 6 | name: jio-store-service 7 | jpa: 8 | show-sql: true 9 | hibernate: 10 | ddl-auto: create 11 | 12 | # disable eureka by default 13 | 14 | eureka: 15 | client: 16 | enabled: false -------------------------------------------------------------------------------- /jio-store-service/src/test/java/com/barath/jio/app/JioStoreServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.jio.app; 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 JioStoreServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /k8s/k8s.yaml: -------------------------------------------------------------------------------- 1 | 2 | # config map to pass environment variables to containers 3 | apiVersion: v1 4 | data: 5 | spring.profiles.active: k8s,path 6 | kind: ConfigMap 7 | metadata: 8 | name: spring-config-map 9 | 10 | --- 11 | # config map to pass environment variables to gateway-service 12 | apiVersion: v1 13 | data: 14 | jio.service.url: http://jio-service:9501 15 | jio.service.id: jio-service 16 | jio.service.path: Path= /jio/* 17 | airtel.service.url: http://airtel-service:9502 18 | airtel.service.id: airtel-service 19 | airtel.service.path: Path= /airtel/* 20 | vodaphone.service.url: http://vodaphone-service:9503 21 | vodaphone.service.id: vodaphone-service 22 | vodaphone.service.path: Path= /vodaphone/* 23 | kind: ConfigMap 24 | metadata: 25 | name: api-gateway-config-map 26 | --- 27 | 28 | # deployment config for spring cloud gateway service 29 | 30 | apiVersion: apps/v1 31 | kind: Deployment 32 | metadata: 33 | name: gateway-service 34 | spec: 35 | selector: 36 | matchLabels: 37 | app: gateway-service 38 | replicas: 1 39 | template: 40 | metadata: 41 | labels: 42 | app: gateway-service 43 | spec: 44 | containers: 45 | - name: gateway-service 46 | image: barathece91/gateway-service-k8s 47 | ports: 48 | - containerPort: 9500 49 | env: 50 | - name: SPRING_PROFILES_ACTIVE 51 | valueFrom: 52 | configMapKeyRef: 53 | name: spring-config-map 54 | key: spring.profiles.active 55 | - name: SPRING_CLOUD_GATEWAY_ROUTES_0_URI 56 | valueFrom: 57 | configMapKeyRef: 58 | name: api-gateway-config-map 59 | key: jio.service.url 60 | - name: SPRING_CLOUD_GATEWAY_ROUTES_0_ID 61 | valueFrom: 62 | configMapKeyRef: 63 | name: api-gateway-config-map 64 | key: jio.service.id 65 | - name: SPRING_CLOUD_GATEWAY_ROUTES_0_PREDICATES_0_ 66 | valueFrom: 67 | configMapKeyRef: 68 | name: api-gateway-config-map 69 | key: jio.service.path 70 | - name: SPRING_CLOUD_GATEWAY_ROUTES_0_FILTERS_0_ 71 | value: StripPrefix=1 72 | - name: SPRING_CLOUD_GATEWAY_ROUTES_1_URI 73 | valueFrom: 74 | configMapKeyRef: 75 | name: api-gateway-config-map 76 | key: airtel.service.url 77 | - name: SPRING_CLOUD_GATEWAY_ROUTES_1_ID 78 | valueFrom: 79 | configMapKeyRef: 80 | name: api-gateway-config-map 81 | key: airtel.service.id 82 | - name: SPRING_CLOUD_GATEWAY_ROUTES_1_PREDICATES_0_ 83 | valueFrom: 84 | configMapKeyRef: 85 | name: api-gateway-config-map 86 | key: airtel.service.path 87 | - name: SPRING_CLOUD_GATEWAY_ROUTES_2_FILTERS_0_ 88 | value: StripPrefix=1 89 | - name: SPRING_CLOUD_GATEWAY_ROUTES_2_URI 90 | valueFrom: 91 | configMapKeyRef: 92 | name: api-gateway-config-map 93 | key: vodaphone.service.url 94 | - name: SPRING_CLOUD_GATEWAY_ROUTES_2_ID 95 | valueFrom: 96 | configMapKeyRef: 97 | name: api-gateway-config-map 98 | key: vodaphone.service.id 99 | - name: SPRING_CLOUD_GATEWAY_ROUTES_2_PREDICATES_0_ 100 | valueFrom: 101 | configMapKeyRef: 102 | name: api-gateway-config-map 103 | key: vodaphone.service.path 104 | - name: SPRING_CLOUD_GATEWAY_ROUTES_2_FILTERS_0_ 105 | value: StripPrefix=1 106 | 107 | --- 108 | # deployment config for vodaphone-store-service 109 | 110 | apiVersion: apps/v1 111 | kind: Deployment 112 | metadata: 113 | name: vodaphone-service 114 | spec: 115 | selector: 116 | matchLabels: 117 | app: vodaphone-service 118 | replicas: 1 119 | template: 120 | metadata: 121 | labels: 122 | app: vodaphone-service 123 | spec: 124 | containers: 125 | - name: vodaphone-service 126 | image: barathece91/vodaphone-service-k8s 127 | ports: 128 | - containerPort: 9503 129 | env: 130 | - name: SPRING_PROFILES_ACTIVE 131 | valueFrom: 132 | configMapKeyRef: 133 | name: spring-config-map 134 | key: spring.profiles.active 135 | --- 136 | 137 | 138 | # deployment config for jio-store-service 139 | 140 | apiVersion: apps/v1 141 | kind: Deployment 142 | metadata: 143 | name: jio-service 144 | spec: 145 | selector: 146 | matchLabels: 147 | app: jio-service 148 | replicas: 1 149 | template: 150 | metadata: 151 | labels: 152 | app: jio-service 153 | spec: 154 | containers: 155 | - name: jio-service 156 | image: barathece91/jio-service-k8s 157 | ports: 158 | - containerPort: 9501 159 | env: 160 | - name: SPRING_PROFILES_ACTIVE 161 | valueFrom: 162 | configMapKeyRef: 163 | name: spring-config-map 164 | key: spring.profiles.active 165 | 166 | --- 167 | 168 | # deployment config for airtel-store-service 169 | 170 | apiVersion: apps/v1 171 | kind: Deployment 172 | metadata: 173 | name: airtel-service 174 | spec: 175 | selector: 176 | matchLabels: 177 | app: airtel-service 178 | replicas: 1 179 | template: 180 | metadata: 181 | labels: 182 | app: airtel-service 183 | spec: 184 | containers: 185 | - name: airtel-service 186 | image: barathece91/airtel-service-k8s 187 | ports: 188 | - containerPort: 9502 189 | --- 190 | kind: Service 191 | apiVersion: v1 192 | metadata: 193 | name: gateway-service 194 | spec: 195 | selector: 196 | app: gateway-service 197 | type: ClusterIP 198 | ports: 199 | - protocol: TCP 200 | port: 9500 201 | targetPort: 9500 202 | --- 203 | kind: Service 204 | apiVersion: v1 205 | metadata: 206 | name: jio-service 207 | spec: 208 | selector: 209 | app: jio-service 210 | type: ClusterIP 211 | ports: 212 | - protocol: TCP 213 | port: 9501 214 | targetPort: 9501 215 | 216 | --- 217 | kind: Service 218 | apiVersion: v1 219 | metadata: 220 | name: airtel-service 221 | spec: 222 | selector: 223 | app: airtel-service 224 | type: ClusterIP 225 | ports: 226 | - protocol: TCP 227 | port: 9502 228 | targetPort: 9502 229 | --- 230 | 231 | kind: Service 232 | apiVersion: v1 233 | metadata: 234 | name: vodaphone-service 235 | spec: 236 | selector: 237 | app: vodaphone-service 238 | type: ClusterIP 239 | ports: 240 | - protocol: TCP 241 | port: 9503 242 | targetPort: 9503 243 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | spring-cloud-gateway-services 8 | 3.0.0.RELEASE 9 | pom 10 | 11 | spring-cloud-gateway-services 12 | 13 | 14 | 15 | 16 | UTF-8 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | airtel-store-service 24 | jio-store-service 25 | vodaphone-store-service 26 | spring-cloud-gateway 27 | config-server 28 | eureka-server 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-cloud-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/spring-cloud-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-cloud-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /spring-cloud-gateway/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | VOLUME /tmp 5 | ADD target/spring-cloud-gateway-*.jar app.jar 6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /spring-cloud-gateway/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-cloud-gateway/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-cloud-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | spring-cloud-gateway 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | spring-cloud-gateway 12 | spring-cloud-gateway service providing intelligent routing 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-webflux 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-gateway 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-sleuth 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-netflix-eureka-client 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-devtools 52 | runtime 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.cloud 65 | spring-cloud-dependencies 66 | ${spring-cloud.version} 67 | pom 68 | import 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | 79 | 80 | 81 | 82 | 83 | 84 | spring-milestones 85 | Spring Milestones 86 | https://repo.spring.io/milestone 87 | 88 | false 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/java/com/barath/gateway/app/EurekaConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.gateway.app; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | @Profile("eureka") 8 | @Configuration 9 | @EnableDiscoveryClient 10 | public class EurekaConfiguration { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/java/com/barath/gateway/app/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.barath.gateway.app; 2 | 3 | import java.lang.invoke.MethodHandles; 4 | import java.util.Objects; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.SpringApplication; 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; 13 | import org.springframework.cloud.gateway.config.GatewayProperties; 14 | 15 | @SpringBootApplication 16 | public class GatewayApplication { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 19 | 20 | @Autowired 21 | private GatewayProperties props; 22 | 23 | public static void main(String[] args) { 24 | SpringApplication.run(GatewayApplication.class, args); 25 | } 26 | 27 | @PostConstruct 28 | public void init() { 29 | logger.info(Objects.toString(props)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | enabled: true 4 | register-with-eureka: true 5 | fetch-registry: true 6 | service-url: 7 | default-zone: http://localhost:8761/eureka 8 | -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/resources/application-header.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | cloud: 4 | gateway: 5 | routes: 6 | - id: jio-service 7 | uri: http://localhost:9501 8 | predicates: 9 | - Header= store,jio 10 | - id: airtel-service 11 | uri: http://localhost:9502 12 | predicates: 13 | - Header= store,airtel 14 | - id: vodaphone-service 15 | uri: http://localhost:9503 16 | predicates: 17 | - Header= store,vodaphone -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/resources/application-path.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | cloud: 4 | gateway: 5 | routes: 6 | - id: jio-service 7 | uri: http://localhost:9501 8 | predicates: 9 | - Path= /jio/* 10 | filters: 11 | - StripPrefix=1 # required to strip the prefix made to the request . Ex /jio/customers request will go to jio service as /customers 12 | - id: airtel-service 13 | uri: http://localhost:9502 14 | predicates: 15 | - Path= /airtel/* 16 | filters: 17 | - StripPrefix=1 18 | - id: vodaphone-service 19 | uri: http://localhost:9503 20 | predicates: 21 | - Path= /vodaphone/* 22 | filters: 23 | - StripPrefix=1 -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/resources/application-query.yml: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring: 4 | cloud: 5 | gateway: 6 | routes: 7 | - id: jio-service 8 | uri: http://localhost:9501 9 | predicates: 10 | - Query= store,jio 11 | - id: airtel-service 12 | uri: http://localhost:9502 13 | predicates: 14 | - Query= store,airtel 15 | - id: vodaphone-service 16 | uri: http://localhost:9503 17 | predicates: 18 | - Query= store,vodaphone -------------------------------------------------------------------------------- /spring-cloud-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9500 3 | 4 | logging: 5 | level: 6 | org.springframework.web: DEBUG 7 | # pattern: 8 | # level: "[%X{X-B3-TraceId}/%X{X-B3-SpanId}] %-5p [%t] %C{2} - %m%n" 9 | 10 | 11 | spring: 12 | profiles: 13 | active: path # path | header | query are the other spring profiles for other strategies 14 | application: 15 | name: api-gateway 16 | # disable eureka by default 17 | 18 | eureka: 19 | client: 20 | enabled: false -------------------------------------------------------------------------------- /spring-cloud-gateway/src/test/java/com/barath/gateway/app/SpringCloudGatewayApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.gateway.app; 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 SpringCloudGatewayApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vodaphone-store-service/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /vodaphone-store-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BarathArivazhagan/spring-cloud-gateway-routing/1ccdc664a817da0d64793a2cc351eca34744aaa7/vodaphone-store-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /vodaphone-store-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /vodaphone-store-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN adduser -D demo 3 | USER demo 4 | VOLUME /tmp 5 | ADD target/vodaphone-store-service-*.jar app.jar 6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /vodaphone-store-service/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /vodaphone-store-service/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /vodaphone-store-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.barath.microservices 7 | vodaphone-store-service 8 | 3.0.0.RELEASE 9 | jar 10 | 11 | vodaphone-store-service 12 | vodaphone-store-service microservice 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Greenwich.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-jpa 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-webflux 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-devtools 45 | runtime 46 | 47 | 48 | org.hsqldb 49 | hsqldb 50 | runtime 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-starter-test 55 | test 56 | 57 | 58 | org.springframework.cloud 59 | spring-cloud-starter-netflix-eureka-client 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.cloud 75 | spring-cloud-dependencies 76 | ${spring-cloud.version} 77 | pom 78 | import 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/Application.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/configuration/EurekaConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.configuration; 2 | 3 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | @Profile("eureka") 8 | @Configuration 9 | @EnableDiscoveryClient 10 | public class EurekaConfiguration { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/configuration/RouterConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.configuration; 2 | 3 | import com.barath.vodaphone.app.handler.CustomerHandler; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.RouterFunctions; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | 11 | import static org.springframework.web.reactive.function.server.RequestPredicates.GET; 12 | import static org.springframework.web.reactive.function.server.RequestPredicates.POST; 13 | import static org.springframework.web.reactive.function.server.RequestPredicates.accept; 14 | 15 | 16 | /** 17 | * Created by barath on 03/03/18. 18 | */ 19 | @Configuration 20 | public class RouterConfiguration { 21 | 22 | private CustomerHandler customerHandler; 23 | 24 | public RouterConfiguration(CustomerHandler customerHandler){ 25 | this.customerHandler=customerHandler; 26 | } 27 | 28 | @Bean 29 | public RouterFunction routes(){ 30 | 31 | return RouterFunctions 32 | .route(POST("/customer/add") 33 | .and(accept(MediaType.APPLICATION_JSON_UTF8)),customerHandler::addCustomer) 34 | .andRoute(GET("/customer/get/{customerName}"),customerHandler::getCustomer) 35 | .andRoute(GET("/customers"),customerHandler::getCustomers); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | 6 | import javax.persistence.*; 7 | 8 | /** 9 | * Created by barath on 03/03/18. 10 | */ 11 | @Entity 12 | @Table(name = "CUSTOMER") 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | public class Customer { 15 | 16 | @Id 17 | @GeneratedValue 18 | @JsonIgnore 19 | @Column(name = "CUSTOMER_ID") 20 | private Long customerId; 21 | 22 | @Column(name = "CUSTOMER_NAME",nullable = false,length = 100) 23 | private String customerName; 24 | 25 | @Column(name = "CUSTOMER_AGE",nullable = false,length = 3) 26 | private int customerAge; 27 | 28 | 29 | @Enumerated(EnumType.STRING) 30 | @Column(name = "CUSTOMER_GENDER",length = 10) 31 | private CustomerGender customerGender; 32 | 33 | public enum CustomerGender{ 34 | MALE,FEMALE 35 | } 36 | 37 | public Customer(Long customerId, String customerName, int customerAge, CustomerGender customerGender) { 38 | this.customerId = customerId; 39 | this.customerName = customerName; 40 | this.customerAge = customerAge; 41 | this.customerGender = customerGender; 42 | } 43 | 44 | public Customer(String customerName, int customerAge, CustomerGender customerGender) { 45 | this.customerName = customerName; 46 | this.customerAge = customerAge; 47 | this.customerGender = customerGender; 48 | } 49 | 50 | protected Customer() { 51 | } 52 | 53 | public Long getCustomerId() { 54 | return customerId; 55 | } 56 | 57 | public void setCustomerId(Long customerId) { 58 | this.customerId = customerId; 59 | } 60 | 61 | public String getCustomerName() { 62 | return customerName; 63 | } 64 | 65 | public void setCustomerName(String customerName) { 66 | this.customerName = customerName; 67 | } 68 | 69 | public int getCustomerAge() { 70 | return customerAge; 71 | } 72 | 73 | public void setCustomerAge(int customerAge) { 74 | this.customerAge = customerAge; 75 | } 76 | 77 | public CustomerGender getCustomerGender() { 78 | return customerGender; 79 | } 80 | 81 | public void setCustomerGender(CustomerGender customerGender) { 82 | this.customerGender = customerGender; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Customer{" + 88 | "customerId=" + customerId + 89 | ", customerName='" + customerName + '\'' + 90 | ", customerAge=" + customerAge + 91 | ", customerGender=" + customerGender + 92 | '}'; 93 | } 94 | 95 | @Override 96 | public boolean equals(Object o) { 97 | if (this == o) return true; 98 | if (o == null || getClass() != o.getClass()) return false; 99 | 100 | Customer customer = (Customer) o; 101 | 102 | if (customerAge != customer.customerAge) return false; 103 | if (customerId != null ? !customerId.equals(customer.customerId) : customer.customerId != null) return false; 104 | if (customerName != null ? !customerName.equals(customer.customerName) : customer.customerName != null) 105 | return false; 106 | return customerGender == customer.customerGender; 107 | } 108 | 109 | @Override 110 | public int hashCode() { 111 | int result = customerId != null ? customerId.hashCode() : 0; 112 | result = 31 * result + (customerName != null ? customerName.hashCode() : 0); 113 | result = 31 * result + customerAge; 114 | result = 31 * result + (customerGender != null ? customerGender.hashCode() : 0); 115 | return result; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/handler/CustomerHandler.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.handler; 2 | 3 | import com.barath.vodaphone.app.entity.Customer; 4 | import com.barath.vodaphone.app.service.CustomerService; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.reactive.function.server.ServerRequest; 10 | import org.springframework.web.reactive.function.server.ServerResponse; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.lang.invoke.MethodHandles; 14 | 15 | /** 16 | * Created by barath on 03/03/18. 17 | */ 18 | 19 | @Component 20 | public class CustomerHandler { 21 | 22 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 23 | 24 | private CustomerService customerService; 25 | 26 | public CustomerHandler(CustomerService customerService) { 27 | this.customerService=customerService; 28 | } 29 | 30 | public Mono addCustomer(ServerRequest serverRequest){ 31 | 32 | return ServerResponse 33 | .ok() 34 | .contentType(MediaType.APPLICATION_JSON_UTF8) 35 | .body(customerService.addCustomer(serverRequest.bodyToMono(Customer.class)),Customer.class) 36 | .log(); 37 | } 38 | 39 | public Mono getCustomer(ServerRequest serverRequest){ 40 | 41 | return ServerResponse 42 | .ok() 43 | .contentType(MediaType.APPLICATION_JSON_UTF8) 44 | .body(customerService.getCustomer(serverRequest.pathVariable("customerName")),Customer.class) 45 | .log(); 46 | } 47 | 48 | public Mono getCustomers(ServerRequest serverRequest){ 49 | 50 | return ServerResponse 51 | .ok() 52 | .contentType(MediaType.APPLICATION_JSON_UTF8) 53 | .body(customerService.getCustomers(),Customer.class) 54 | .log(); 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.repository; 2 | 3 | import com.barath.vodaphone.app.entity.Customer; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * Created by barath on 03/03/18. 8 | */ 9 | public interface CustomerRepository extends JpaRepository { 10 | 11 | Customer findByCustomerName(String customerName); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/java/com/barath/vodaphone/app/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app.service; 2 | 3 | import com.barath.vodaphone.app.entity.Customer; 4 | import com.barath.vodaphone.app.repository.CustomerRepository; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Service; 9 | import reactor.core.publisher.Flux; 10 | import reactor.core.publisher.Mono; 11 | 12 | import javax.annotation.PostConstruct; 13 | import java.lang.invoke.MethodHandles; 14 | import java.util.Arrays; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by barath on 03/03/18. 19 | */ 20 | @Service 21 | public class CustomerService { 22 | 23 | private CustomerRepository customerRepository; 24 | private static final Logger logger= LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 25 | 26 | public CustomerService(CustomerRepository customerRepository) { 27 | this.customerRepository = customerRepository; 28 | } 29 | 30 | public Mono addCustomer(Mono customerMono){ 31 | 32 | return customerMono 33 | .doOnNext(customerRepository::save).doOnError( error -> { 34 | logger.error("error in creating a customer {}",error.getMessage()); 35 | }); 36 | } 37 | 38 | public Mono getCustomer(String customerName){ 39 | 40 | return Mono.just(customerRepository.findByCustomerName(customerName)); 41 | } 42 | 43 | public Flux getCustomers(){ 44 | 45 | return Flux.fromIterable(customerRepository.findAll()).log(); 46 | } 47 | 48 | /** 49 | * pre load customers for testing for in memory DB 50 | */ 51 | 52 | @PostConstruct 53 | public void init(){ 54 | 55 | customerRepository.saveAll(Arrays.asList(new Customer("barath-vodaphone", 25, Customer.CustomerGender.MALE))); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/resources/application-eureka.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | enabled: true 4 | register-with-eureka: true 5 | fetch-registry: true 6 | service-url: 7 | default-zone: http://localhost:8761/eureka 8 | -------------------------------------------------------------------------------- /vodaphone-store-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9503 3 | 4 | spring: 5 | application: 6 | name: vodaphone-store-service 7 | jpa: 8 | show-sql: true 9 | hibernate: 10 | ddl-auto: create 11 | 12 | # disable eureka by default 13 | 14 | eureka: 15 | client: 16 | enabled: false -------------------------------------------------------------------------------- /vodaphone-store-service/src/test/java/com/barath/vodaphone/app/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.barath.vodaphone.app; 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 ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------