module
0.0.0-20240529091543-59fe605d7f9b
Repository: https://github.com/adipp/go-event-driven.git
Documentation: pkg.go.dev
# README
Event-Driven Architecture in Go
This project demonstrates an event-driven architecture using Go. It includes a simple example of creating an order, processing order payment, updating stock movement, and sending an order email.
Table of Contents
Getting Started
Prerequisites
- Go 1.16 or higher
- RabbitMQ
Installation
-
Clone the repository:
git clone https://github.com/AdiPP/go-event-driven.git cd go-event-driven
-
Install dependencies:
go mod tidy
-
Ensure RabbitMQ is running locally:
docker compose up -d
Architecture
The project is structured as follows:
main.go
: The entry point of the application.internal/application/controller
: Contains the HTTP controllers.internal/application/usecase
: Contains the use cases for the application.internal/domain/event
: Contains the domain events.internal/infra/queue
: Contains the queue adapter implementation (RabbitMQ in this case).
Flow
- The client sends a POST request to create an order.
- The
OrderController
handles the request and triggers theCreateOrderUseCase
. - The
CreateOrderUseCase
publishes anOrderCreatedEvent
to the RabbitMQ queue. - The application listens for the
OrderCreatedEvent
and processes it through various handlers:ProcessOrderPayment
,StockMovement
, andSendOrderEmail
.
Usage
Running the Application
-
Start the application:
go run main.go
-
The server will start and listen on port 8080.
API Endpoints
- Create Order:
POST /create-order
- This endpoint is used to create a new order.
Example Request
curl -X POST http://localhost:8080/create-order -H "Accept: application/json" -H "Content-Type: application/json" -d '{"items":[{"product_id":"1","qtd":10}]}'
Sample Screenshots
API Request
RabbitMQ Management
Console Output
Contributing
Contributions are welcome! Please fork this repository and submit a pull request.
License
This project is licensed under the MIT License.
# Packages
No description provided by the author