diff --git a/pay-app-spring-microservices/app-invoice/build.gradle b/pay-app-spring-microservices/app-invoice/build.gradle index 76d0556..5cba445 100644 --- a/pay-app-spring-microservices/app-invoice/build.gradle +++ b/pay-app-spring-microservices/app-invoice/build.gradle @@ -28,6 +28,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.kafka:spring-kafka' implementation 'org.springframework.cloud:spring-cloud-starter-config' + implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' + implementation 'org.springframework.boot:spring-boot-starter-actuator' compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.postgresql:postgresql' diff --git a/pay-app-spring-microservices/app-invoice/src/main/resources/application.properties b/pay-app-spring-microservices/app-invoice/src/main/resources/application.properties index 8b13789..52aa948 100644 --- a/pay-app-spring-microservices/app-invoice/src/main/resources/application.properties +++ b/pay-app-spring-microservices/app-invoice/src/main/resources/application.properties @@ -1 +1,5 @@ - +# Consul +spring.cloud.consul.host=consul +spring.cloud.consul.port=8500 +spring.cloud.consul.discovery.health-check-interval=5s +spring.cloud.consul.discovery.prefer-ip-address=true \ No newline at end of file diff --git a/pay-app-spring-microservices/app-pay/build.gradle b/pay-app-spring-microservices/app-pay/build.gradle index fdaf2e0..b37c92f 100644 --- a/pay-app-spring-microservices/app-pay/build.gradle +++ b/pay-app-spring-microservices/app-pay/build.gradle @@ -28,6 +28,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.kafka:spring-kafka' implementation 'org.springframework.cloud:spring-cloud-starter-config' + implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + compileOnly 'org.projectlombok:lombok' runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.projectlombok:lombok' diff --git a/pay-app-spring-microservices/app-pay/src/main/resources/application.properties b/pay-app-spring-microservices/app-pay/src/main/resources/application.properties index 8b13789..52aa948 100644 --- a/pay-app-spring-microservices/app-pay/src/main/resources/application.properties +++ b/pay-app-spring-microservices/app-pay/src/main/resources/application.properties @@ -1 +1,5 @@ - +# Consul +spring.cloud.consul.host=consul +spring.cloud.consul.port=8500 +spring.cloud.consul.discovery.health-check-interval=5s +spring.cloud.consul.discovery.prefer-ip-address=true \ No newline at end of file diff --git a/pay-app-spring-microservices/app-transaction/build.gradle b/pay-app-spring-microservices/app-transaction/build.gradle index 1ca3403..8a6416c 100644 --- a/pay-app-spring-microservices/app-transaction/build.gradle +++ b/pay-app-spring-microservices/app-transaction/build.gradle @@ -27,6 +27,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.kafka:spring-kafka' implementation 'org.springframework.cloud:spring-cloud-starter-config' + implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/pay-app-spring-microservices/app-transaction/src/main/resources/application.properties b/pay-app-spring-microservices/app-transaction/src/main/resources/application.properties index 8b13789..52aa948 100644 --- a/pay-app-spring-microservices/app-transaction/src/main/resources/application.properties +++ b/pay-app-spring-microservices/app-transaction/src/main/resources/application.properties @@ -1 +1,5 @@ - +# Consul +spring.cloud.consul.host=consul +spring.cloud.consul.port=8500 +spring.cloud.consul.discovery.health-check-interval=5s +spring.cloud.consul.discovery.prefer-ip-address=true \ No newline at end of file diff --git a/pay-app-spring-microservices/appgw/gateway.config.yml b/pay-app-spring-microservices/appgw/gateway.config.yml index 1a7f68b..0445795 100644 --- a/pay-app-spring-microservices/appgw/gateway.config.yml +++ b/pay-app-spring-microservices/appgw/gateway.config.yml @@ -4,12 +4,27 @@ admin: port: 9876 host: localhost apiEndpoints: - appconfig: + app-config: host: localhost - paths: ['/config','/config/*'] + paths: ['/app-config','/app-config/*'] + app-invoice: + host: localhost + paths: ['/app-invoice','/app-invoice/*'] + app-pay: + host: localhost + paths: ['/app-pay','/app-pay/*'] + app-transaction: + host: localhost + paths: ['/app-transaction','/app-transaction/*'] serviceEndpoints: - appconfig: - url: 'http://loadbalancer/config/' + app-config: + url: 'http://loadbalancer/app-config/' + app-invoice: + url: 'http://loadbalancer/app-invoice/' + app-pay: + url: 'http://loadbalancer/app-pay/' + app-transaction: + url: 'http://loadbalancer/app-transaction/' policies: - basic-auth - cors @@ -22,14 +37,38 @@ policies: pipelines: default: apiEndpoints: - - appconfig + - app-config + - app-pay + - app-transaction policies: - # Uncomment `key-auth:` when instructed to in the Getting Started guide. - key-auth: - proxy: - action: - serviceEndpoint: appconfig + serviceEndpoint: app-config + changeOrigin: true + prependPath: false + ignorePath: false + stripPath: false + - action: + serviceEndpoint: app-pay + changeOrigin: true + prependPath: false + ignorePath: false + stripPath: false + - action: + serviceEndpoint: app-transaction changeOrigin: true prependPath: false ignorePath: false stripPath: false + dmz: + apiEndpoints: + - app-invoice + policies: + - proxy: + - action: + serviceEndpoint: app-invoice + changeOrigin: true + prependPath: false + ignorePath: false + stripPath: false \ No newline at end of file diff --git a/pay-app-spring-microservices/commands.md b/pay-app-spring-microservices/commands.md index 4c7fa26..c59fb19 100644 --- a/pay-app-spring-microservices/commands.md +++ b/pay-app-spring-microservices/commands.md @@ -96,3 +96,6 @@ eg credentials create -c sebas -t key-auth -q curl -H "Authorization: apiKey ${keyId}:${keySecret}" http://localhost:8080/config/app-pay/dev curl -H "Authorization: apiKey 3DvE2HCfZCyfgxAjF40tOk:2U4Cojm11JaPJF6WRUcFBL" http://localhost:8080/config/app-pay/dev +curl -H "Authorization: apiKey 7AzWybVM0FaB7mTRadNUGR:5N50F0YcQ7U45JcD5C7J32" http://localhost:8080/app-config/app-pay/dev + +7AzWybVM0FaB7mTRadNUGR:5N50F0YcQ7U45JcD5C7J32 \ No newline at end of file diff --git a/pay-app-spring-microservices/haproxy/haproxy.cfg b/pay-app-spring-microservices/haproxy/haproxy.cfg index 3b54b0c..5112ab9 100644 --- a/pay-app-spring-microservices/haproxy/haproxy.cfg +++ b/pay-app-spring-microservices/haproxy/haproxy.cfg @@ -13,22 +13,40 @@ frontend stats frontend http_front bind *:80 mode http - acl url_config path_beg /config - use_backend config_back if url_config + acl url_app-config path_beg /app-config + use_backend app-config-backend if url_app-config + acl url_app-invoice path_beg /app-invoice + use_backend app-invoice-backend if url_app-invoice + acl url_app-pay path_beg /app-pay + use_backend app-pay-backend if url_app-pay + acl url_app-transaction path_beg /app-transaction + use_backend app-transaction-backend if url_app-transaction - default_backend http_back +backend app-config-backend + mode http + balance roundrobin + http-request set-path "%[path,regsub(^/app-config/,/)]" + server app-config app-config.service.consul:8888 resolvers consul resolve-prefer ipv4 check + +backend app-invoice-backend + mode http + balance roundrobin + http-request set-path "%[path,regsub(^/app-invoice/,/)]" + server app-invoice app-invoice.service.consul:8006 resolvers consul resolve-prefer ipv4 check -backend config_back - mode http - balance roundrobin - http-request set-path "%[path,regsub(^/config/,/)]" - server appconfig app-config.service.consul:8888 resolvers consul resolve-prefer ipv4 check -backend http_back - mode http - balance roundrobin - server-template mywebapp 1-10 _web._tcp.service.consul resolvers consul resolve-prefer ipv4 check +backend app-pay-backend + mode http + balance roundrobin + http-request set-path "%[path,regsub(^/app-pay/,/)]" + server app-pay app-pay.service.consul:8010 resolvers consul resolve-prefer ipv4 check + +backend app-transaction-backend + mode http + balance roundrobin + http-request set-path "%[path,regsub(^/app-transaction/,/)]" + server app-transaction app-transaction.service.consul:8082 resolvers consul resolve-prefer ipv4 check resolvers consul - nameserver consul consul:8600 - accepted_payload_size 8192 - hold valid 5s + nameserver consul consul:8600 + accepted_payload_size 8192 + hold valid 5s diff --git a/pay-app-spring-microservices/resources/postgres/postgres.sql b/pay-app-spring-microservices/resources/postgres/1-postgres.sql similarity index 100% rename from pay-app-spring-microservices/resources/postgres/postgres.sql rename to pay-app-spring-microservices/resources/postgres/1-postgres.sql diff --git a/pay-app-spring-microservices/resources/postgres/data.sql b/pay-app-spring-microservices/resources/postgres/2-data.sql similarity index 100% rename from pay-app-spring-microservices/resources/postgres/data.sql rename to pay-app-spring-microservices/resources/postgres/2-data.sql diff --git a/pay-app-spring-microservices/resources/postgres/Dockerfile b/pay-app-spring-microservices/resources/postgres/Dockerfile index 450d83f..05b5d57 100644 --- a/pay-app-spring-microservices/resources/postgres/Dockerfile +++ b/pay-app-spring-microservices/resources/postgres/Dockerfile @@ -2,5 +2,5 @@ FROM postgres:12-alpine env POSTGRES_PASSWORD=postgres env POSTGRES_DB=db_invoice -COPY ./postgres.sql /docker-entrypoint-initdb.d - +COPY ./1-postgres.sql /docker-entrypoint-initdb.d +COPY ./2-data.sql /docker-entrypoint-initdb.d