A lightweight Go microservice that accepts email jobs over HTTP, queues them, and processes them asynchronously using a concurrent worker pool.
- β HTTP API to enqueue email jobs
- β In-memory job queue with channels
- β Multiple concurrent workers
- β Simulated email delivery
- β Graceful shutdown on SIGINT/SIGTERM
- β Retry failed jobs (up to 3 times)
- β Dead Letter Queue (DLQ) for permanently failed jobs
emailservice/ βββ main.go # Entry point βββ api/ β βββ handler.go # HTTP handlers βββ queue/ β βββ config.go # Queue config β βββ interface.go # Job interface β βββ job.go # Job model β βββ queue.go # Queue logic
Configuration is currently hardcoded in main.go:
cfg := queue.Config{
QueueSize: 10,
WorkerCount: 3,
}
## How to Run
go run main.go
## π¬ API Endpoints
### 1. `POST /send-email`
Enqueue a new email job.
#### π Request Payload
```json
{
"to": "[email protected]",
"subject": "Welcome!",
"body": "Thanks for signing up."
}
curl -X POST http://localhost:8080/send-email \
-H "Content-Type: application/json" \
-d '{
"to": "[email protected]",
"subject": "Welcome!",
"body": "Thanks for signing up."
}'