This project is a system that automatically sends unsent messages from the database at specified intervals.
- Automatically sends 2 unsent messages every 2 minutes
 - Start/stop message sending APIs
 - List sent messages API
 - Redis cache support
 - Swagger documentation
 
- Clone the repository:
 
git clone https://github.com/ridvanuyn/messaging-system-go.git
cd messaging-system-go- Start with Docker Compose:
 
docker-compose up -dThis command will start the application, PostgreSQL database, and Redis.
- Go 1.24 or higher is required
 - PostgreSQL and Redis must be installed
 - Create the database and run the migrations/init.sql file
 - Install the required dependencies:
 
go mod download- Build and run the application:
 
go build -o messaging-app ./cmd/server
./messaging-appThe application can be configured with the following environment variables:
PORT: Server port (default: 8080)DATABASE_URL: PostgreSQL connection informationREDIS_URL: Redis connection informationWEBHOOK_URL: Webhook URL where messages will be sentAUTH_KEY: Authentication key for the webhookMAX_CONTENT_LENGTH: Maximum message length (default: 160)
Swagger documentation can be accessed at http://localhost:8080/swagger/index.html.
- 
Start Scheduler:
POST /api/scheduler/start - 
Stop Scheduler:
POST /api/scheduler/stop - 
Query Scheduler Status:
GET /api/scheduler/status - 
List Sent Messages:
GET /api/messages 
You can test message sending using Webhook.site:
- Go to Webhook.site
 - Copy the special URL given to you
 - Update the 
WEBHOOK_URLvariable in the Docker Compose file - Restart the application
 - Monitor incoming requests from the Webhook.site panel
 
This Go application works as follows:
- 
Startup: When the application starts, the scheduler automatically starts and begins processing unsent messages in the database.
 - 
Periodic Operation: Every 2 minutes, it selects the 2 oldest unsent messages.
 - 
Message Sending: It sends the selected messages to the webhook API and processes the response.
 - 
Status Update: It updates the status of successfully sent messages in the database and records the sending IDs.
 - 
Redis Cache: It saves the sent message IDs and sending time to Redis (bonus feature).