129 lines
5.3 KiB
Markdown
129 lines
5.3 KiB
Markdown
# Send an invoice for processing
|
|
curl -X POST http://localhost:7777/api/facturas/enviar \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"transaccion_id": "4671b0e9-adae-4de9-86c5-e384616626d6", "estado": "PENDIENTE", "numero_factura": "F001-02413224482"}'
|
|
|
|
# Query invoice status
|
|
curl -X GET http://localhost:7777/api/facturas/4671b0e9-adae-4de9-86c5-e384616626d6
|
|
|
|
# Revert an invoice
|
|
curl -X POST http://localhost:7777/api/facturas/revertir \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"transaccion_id": "4671b0e9-adae-4de9-86c5-e384616626d6", "numero_factura": "F001-02413224482"}'
|
|
|
|
# Reprocess DLQ messages
|
|
curl -X POST http://localhost:7777/api/dlq/reprocesar
|
|
|
|
|
|
# topic
|
|
# Entra al contenedor de kafka
|
|
docker exec -it <kafka_container_id> bash
|
|
|
|
# Una vez dentro, crea los topics
|
|
kafka-topics.sh --create --bootstrap-server localhost:9093 --topic FACTURACION --partitions 1 --replication-factor 1
|
|
|
|
kafka-topics.sh --create --bootstrap-server localhost:9093 --topic FACTURACION_RESULTADOS --partitions 1 --replication-factor 1
|
|
|
|
kafka-topics.sh --create --bootstrap-server localhost:9093 --topic FACTURACION_DLQ --partitions 1 --replication-factor 1
|
|
|
|
# FACTURACION
|
|
docker exec facturacion_redis_kafka-kafka-1 kafka-topics --create --bootstrap-server localhost:9093 --topic FACTURACION --partitions 1 --replication-factor 1
|
|
|
|
# FACTURACION_RESULTADOS
|
|
docker exec facturacion_redis_kafka-kafka-1 kafka-topics --create --bootstrap-server localhost:9093 --topic FACTURACION_RESULTADOS --partitions 1 --replication-factor 1
|
|
|
|
# FACTURACION_DLQ
|
|
docker exec facturacion_redis_kafka-kafka-1 kafka-topics --create --bootstrap-server localhost:9093 --topic FACTURACION_DLQ --partitions 1 --replication-factor 1
|
|
|
|
|
|
# CONSTRUIR EJECUTABLE
|
|
# Compilar el código
|
|
go build -o consumer-service cmd/consumer/main.go
|
|
go build -o producer-service cmd/producer/main.go
|
|
|
|
# para compilar en linux desde windows
|
|
env GOOS=linux GOARCH=amd64 go build -o consumer-service cmd/consumer/main.go
|
|
env GOOS=linux GOARCH=amd64 go build -o producer-service cmd/producer/main.go
|
|
|
|
# Ejecutar el servicio
|
|
./producer-service
|
|
./consumer-service
|
|
|
|
# proyecto-consumer
|
|
consumer/
|
|
├── cmd/
|
|
│ └── server/
|
|
│ └── main.go # Punto de entrada de la aplicación
|
|
├── internal/
|
|
│ ├── api/
|
|
│ │ ├── handlers/
|
|
│ │ │ ├── factura.go # Handlers de facturación
|
|
│ │ │ ├── dlq.go # Handlers de DLQ
|
|
│ │ │ └── middleware.go # Middlewares
|
|
│ │ ├── router.go # Configuración de rutas
|
|
│ │ └── server.go # Configuración del servidor HTTP
|
|
│ ├── config/
|
|
│ │ └── config.go # Gestión de configuración
|
|
│ ├── domain/
|
|
│ │ └── models/
|
|
│ │ ├── factura.go # Modelos de dominio
|
|
│ │ ├── response.go # Estructuras de respuesta
|
|
│ │ └── error.go # Errores de dominio
|
|
│ ├── infrastructure/
|
|
│ │ ├── database/
|
|
│ │ │ ├── postgres.go # Cliente de base de datos
|
|
│ │ │ └── repositories/
|
|
│ │ │ ├── factura.go # Repositorio de facturas
|
|
│ │ │ └── dlq.go # Repositorio DLQ
|
|
│ │ ├── kafka/
|
|
│ │ │ └── client.go # Cliente Kafka
|
|
│ │ └── logger/
|
|
│ │ └── logger.go # Sistema de logs
|
|
│ └── services/
|
|
│ ├── factura_service.go # Lógica de negocio
|
|
│ └── dlq_service.go # Servicios DLQ
|
|
├── pkg/
|
|
│ ├── env/
|
|
│ │ └── env.go # Utilidades para variables de entorno
|
|
│ └── utils/
|
|
│ └── utils.go # Utilidades generales
|
|
├── .env.example # Ejemplo de configuración
|
|
├── go.mod # Dependencias del proyecto
|
|
├── go.sum # Verificación de dependencias
|
|
└── README.md # Documentación
|
|
|
|
# CREAR carpetas-archivos
|
|
mkdir -p consumer/cmd/server \
|
|
consumer/internal/api/handlers \
|
|
consumer/internal/config \
|
|
consumer/internal/domain/models \
|
|
consumer/internal/infrastructure/database/repositories \
|
|
consumer/internal/infrastructure/kafka \
|
|
consumer/internal/infrastructure/logger \
|
|
consumer/internal/services \
|
|
consumer/pkg/env \
|
|
consumer/pkg/utils && \
|
|
touch consumer/cmd/server/main.go \
|
|
consumer/internal/api/handlers/factura.go \
|
|
consumer/internal/api/handlers/dlq.go \
|
|
consumer/internal/api/handlers/middleware.go \
|
|
consumer/internal/api/router.go \
|
|
consumer/internal/api/server.go \
|
|
consumer/internal/config/config.go \
|
|
consumer/internal/domain/models/factura.go \
|
|
consumer/internal/domain/models/response.go \
|
|
consumer/internal/domain/models/error.go \
|
|
consumer/internal/infrastructure/database/postgres.go \
|
|
consumer/internal/infrastructure/database/repositories/factura.go \
|
|
consumer/internal/infrastructure/database/repositories/dlq.go \
|
|
consumer/internal/infrastructure/kafka/client.go \
|
|
consumer/internal/infrastructure/logger/logger.go \
|
|
consumer/internal/services/factura_service.go \
|
|
consumer/internal/services/dlq_service.go \
|
|
consumer/pkg/env/env.go \
|
|
consumer/pkg/utils/utils.go \
|
|
consumer/.env.example \
|
|
consumer/go.mod \
|
|
consumer/go.sum \
|
|
consumer/README.md
|