This project implements a microservices-based system for processing user signup events using RabbitMQ as the message broker. The system consists of multiple services that handle different aspects of user signup processing, including email notifications and PDF invoice generation.
The system is composed of the following components:
- Publisher Service: Publishes user signup events to RabbitMQ
- Email Service: Consumes events and sends welcome emails to new users
- PDF Service: Consumes events and generates PDF invoices for new users
- Go 1.16 or higher
- RabbitMQ server
- SMTP server (or MailHog for local development)
.
├── cmd/
│ ├── publisher/ # Event publisher service
│ ├── email_services/ # Email processing service
│ └── pdf_services/ # PDF generation service
├── pkg/
│ ├── common/ # Shared utilities and types
│ ├── emails/ # Email templates and utilities
│ └── pdf_invoice/ # PDF generation utilities
└── .env # Environment configuration
# Initialize Go modules (if not already done)
go mod init user-signup-rabbitmq
# Install and tidy up dependencies
go mod tidyCreate a .env file in the root directory with the following variables:
# RabbitMQ Configuration
RABBITMQ_URL=amqp://guest:guest@localhost:5672/
# SMTP Configuration
SMTP_HOST=localhost
SMTP_PORT=1025 # Default MailHog port# Using Docker
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management# Using Docker
docker run -d --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhogOpen separate terminal windows for each service:
# Terminal 1 - Publisher Service
cd cmd/publisher
go run main.go
# Terminal 2 - Email Service
cd cmd/email_services
go run main.go
# Terminal 3 - PDF Service
cd cmd/pdf_services
go run main.go- The publisher service will automatically send a test user signup event
- The email service will process the event and send a welcome email
- The PDF service will generate an invoice PDF for the new user
- RabbitMQ Management Interface: http://localhost:15672 (guest/guest)
- MailHog Web Interface: http://localhost:8025
- Create a new directory under
cmd/ - Implement the service using the common package utilities
- Set up RabbitMQ consumer/producer as needed
The pkg/common package provides shared functionality:
ConnectRabbitMQ(): Establishes connection to RabbitMQSetupExchange(): Configures the message exchangeUserEvent: Common event structure for user signups
- Services implement retry mechanisms for failed operations
- Messages are acknowledged only after successful processing
- Failed messages are requeued for retry