Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added 02-todo-web-application-h2/.DS_Store
Binary file not shown.
Binary file modified 03-todo-web-application-mysql/.DS_Store
Binary file not shown.
Binary file added iflixapp/.DS_Store
Binary file not shown.
Binary file added pay-app-spring-microservices/.DS_Store
Binary file not shown.
161 changes: 142 additions & 19 deletions pay-app-spring-microservices/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,148 @@
# Microservicios con Spring Boot
# Spring Boot Payment Microservices Application 🚀

![Architecture](./resources/microservicesarchitecture.png)
![Infrastructure](./resources/assets/infrastructure.png)

## Información de los microservicios
El microservicio de invoices, debe listar las facturas de clientes y además debe consumir una cola para cambiar el estado de la factura cuando esta se paga a través del microservicio de pago.
El microservicio de pago debe registrar el pago en su respectiva bd y además debe dejar un mensaje en una cola para actualizar la factura en el microservicio de facturas y además debe dejar un mensaje en una cola para registrar el movimiento en el microservicio de transacciones.
El microservicio de transacciones debe listar las transacciones de una factura, además debe consumir una cola para obtener las transacciones de pago del microservicio de pago.
Todos los microservicios deben consumir la cadena de conexión desde el servicio de configuración centralizada.
## Technologies

La información de los endpoints disponibles por microservicio se incluyen en el documento de INFO.md
## Scripts de creación de bases de datos
- Spring Boot (Java Framework JDK v11+)
- Gradle (Dependency Management)
- Postman (Endpoints Testing)
- Postgresql (Relational Database)
- MySQL (Relational Database)
- MongoDB (Non-Relational Database)
- Kafka (Message Broker)
- Github (Project Repository)

La informacion de como crear las bases de datos y sus respectivas tablas se incluyen en google.com
## Getting Started

## Tecnologías utilizadas
Take into account that you need to have installed the following tools:

- Docker
- Docker Compose

1. Execute the following command to start the microservices:

```bash
./scripts/deploy.sh
```

2. Creation of app gateway user and credentials

```bash
docker exec -it express-gateway sh
./scripts/users.sh
```

## Microservices Information

The **invoices microservice** must list customer invoices and must also consume a queue to change the status of the invoice when it is paid through the payment microservice.

The **payment microservice** must register the payment in its respective database and must also leave a message in a queue to update the invoice in the invoice microservice and must also leave a message in a queue to register the movement in the transaction microservice.

The **transaction microservice** must list the transactions of an invoice, and must also consume a queue to obtain the payment transactions from the payment microservice.

The **configuration microservice** must provide the configuration for all microservices also the most important action is that it provides consul address for service discovery registration.

All microservices must consume the connection string from the centralized configuration service. Information about the endpoints available per microservice is included in the INFO.md document.


## Storage 📜

### PostgreSQL

The PostgreSQL database is used to store the invoices and transactions data and is accessed by the invoices and transactions microservices.

### MySQL

The MySQL database is used to store the payment data and is accessed by the payment microservice.

### MongoDB

The MongoDB database is used to store the transaction data and is accessed by the transaction microservice.

## Networking

### Application Gateway

The application gateway is a reverse proxy that provides a single point of entry for all incoming traffic to the microservices application. It routes requests to the appropriate microservices based on the request URL path. This app gateway is implemented using HAProxy and is configured to use Consul for service discovery and has a redis cache for session management.

### Consul

Consul is a distributed service mesh to connect, secure, and configure services across any runtime platform and public or private cloud. It provides service discovery, health checking, key-value store, and multi-datacenter features.

### HAProxy

This HAProxy configuration is designed to serve as a reverse proxy for HTTP traffic, routing requests based on the URL path to different backend services discovered dynamically using Consul service discovery. It provides timeout settings, load balancing, health checks, and dynamic resolution of backend server addresses.

#### Defaults

The default configuration specifies the following timeout settings:

- timeout connect: Sets the timeout for establishing a connection to the backend server to 5 seconds.
- timeout client: Sets the timeout for the client connection to 1 minute.
- timeout server: Sets the timeout for the server connection to 1 minute.

#### Frontend

1. Stats

- Bind: Listens on port 1936 on all interfaces (*:1936).
- Mode: Configured for HTTP traffic.
- Stats URI: Exposes HAProxy statistics at the root URI ("/").
- Show Legends: Displays legends for the statistics.
- Logging: No logging is enabled for this frontend.

2. http_front

- Bind: Listens on port 80 on all interfaces (*:80).
- Mode: Configured for HTTP traffic.
- ACLs: Defines ACLs based on path for routing to specific backends.
- url_app-config: Routes requests starting with "/app-config" to the app-config-backend.
- url_app-invoice: Routes requests starting with "/app-invoice" to the app-invoice-backend.
- url_app-pay: Routes requests starting with "/app-pay" to the app-pay-backend.
- url_app-transaction: Routes requests starting with "/app-transaction" to the app-transaction-backend.
- Backend Usage: Routes requests to appropriate backends based on ACLs.

#### Backend

- Services: app-config-backend, app-invoice-backend, app-pay-backend, app-transaction-backend
- Mode: Configured for HTTP traffic.
- Balance Algorithm: Uses round-robin load balancing algorithm.
- Path Manipulation: Modifies the request path using http-request set-path.
- Server Configuration: Specifies backend servers with their respective service names and ports.
- Resolvers: Utilizes the consul resolver to resolve backend server addresses dynamically from Consul service discovery.
- Health Checks: Performs health checks on backend servers using check parameter.
- IPv4 Resolution Preference: Specifies IPv4 resolution preference using resolve-prefer ipv4.

#### Resolvers

- Nameserver: Specifies the Consul DNS server address (consul:8600).
- Accepted Payload Size: Sets the maximum payload size accepted from Consul DNS responses.
- Hold Valid: Specifies the validity duration for cached DNS responses as 5 seconds.

## Evidency

### Dnsmasq

![Dnsmasq](./resources/assets/dnsmasq.png)

### Application Gateway

![Application Gateway](./resources/assets/app-gateway.png)

## HAProxy

![HAProxy](./resources/assets/haproxy.png)

## Consul

![Consul](./resources/assets/consul.png)

## Config

![Config](./resources/assets/config.png)

## Services

![Services](./resources/assets/services.png)

- Spring Boot (Java Framework JDK v11+)
- Gradle (Gestor de dependencias)
- Postman (Test de endpoints/servicios rest)
- Postgresql (Base de Datos)
- MySQL (Base de Datos)
- MongoDB (Base de Datos NoSQL)
- Kafka (Gestor de Mensajería)
- Github (Repositorio para proyecto y Configuraciones de micorservicios)
1 change: 1 addition & 0 deletions pay-app-spring-microservices/app-config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ext {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-config-server'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ spring.application.name=app-config
server.port=8888

# Config
spring.cloud.config.server.git.uri=https://github.com/icesi-ops/training_microservices.git
spring.cloud.config.server.git.uri=https://github.com/alejandro945/training-microservices
spring.cloud.config.server.default-label=master
spring.cloud.config.server.git.search-paths=pay-app-spring-microservices/config
spring.cloud.config.server.git.skip-ssl-validation=true
Expand Down
2 changes: 2 additions & 0 deletions pay-app-spring-microservices/app-invoice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ext {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka'
Expand Down
2 changes: 2 additions & 0 deletions pay-app-spring-microservices/app-pay/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ext {


dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka'
Expand Down
2 changes: 2 additions & 0 deletions pay-app-spring-microservices/app-transaction/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ext {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka'
Expand Down
49 changes: 42 additions & 7 deletions pay-app-spring-microservices/appgw/gateway.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@ apiEndpoints:
appconfig:
host: localhost
paths: ['/config','/config/*']
appinvoice:
host: localhost
paths: ['/invoice','/invoice/*']
apppay:
host: localhost
paths: ['/pay','/pay/*']
apptransaction:
host: localhost
paths: ['/transaction','/transaction/*']
serviceEndpoints:
appconfig:
url: 'http://loadbalancer/config/'
appinvoice:
url: 'http://loadbalancer/invoice/'
apppay:
url: 'http://loadbalancer/pay/'
apptransaction:
url: 'http://loadbalancer/transaction/'
policies:
- basic-auth
- cors
Expand All @@ -23,13 +38,33 @@ pipelines:
default:
apiEndpoints:
- appconfig
- apppay
- apptransaction
- appinvoice
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
- key-auth:
- proxy:
- action:
serviceEndpoint: appconfig
changeOrigin: true
prependPath: false
ignorePath: false
stripPath: false
- action:
serviceEndpoint: appconfig
changeOrigin: true
prependPath: false
ignorePath: false
stripPath: false
- action:
serviceEndpoint: apppay
changeOrigin: true
prependPath: false
ignorePath: false
stripPath: false
- action:
serviceEndpoint: apptransaction
changeOrigin: true
prependPath: false
ignorePath: false
stripPath: false
- action:
serviceEndpoint: appinvoice
changeOrigin: true
prependPath: false
ignorePath: false
stripPath: false
98 changes: 0 additions & 98 deletions pay-app-spring-microservices/commands.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Server
spring.application.name=app-invoice
server.port=8006

spring.cloud.consul.discovery.instance-id=invoice-${HOSTNAME}
# Kafka
spring.kafka.consumer.bootstrap-servers=servicekafka:9092
spring.kafka.consumer.bootstrap-servers=servicekafka:9092
Expand Down
8 changes: 7 additions & 1 deletion pay-app-spring-microservices/config/app-pay-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ spring.datasource.url=jdbc:mysql://mysql:3306/db_operation?serverTimezone=Americ
spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect

# 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
Loading