Docker Deployment Guide

This guide explains how to deploy RouteMQ with queue workers using Docker and Docker Compose.

Table of Contents

Architecture Overview

The Docker deployment includes:

┌─────────────────────────────────────────────────────┐
│                  Docker Network                      │
│                                                       │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐          │
│  │  Redis   │  │  MySQL   │  │ RouteMQ  │          │
│  │  :6379   │  │  :3306   │  │   App    │          │
│  └────┬─────┘  └────┬─────┘  └──────────┘          │
│       │             │                                │
│       ├─────────────┼────────────────┐              │
│       │             │                │              │
│  ┌────▼────┐  ┌─────▼────┐  ┌───────▼──────┐      │
│  │ Queue   │  │  Queue   │  │    Queue     │      │
│  │ Worker  │  │  Worker  │  │   Worker     │      │
│  │(default)│  │  (high)  │  │  (emails)    │      │
│  └─────────┘  └──────────┘  └──────────────┘      │
│                                                       │
└─────────────────────────────────────────────────────┘

Services

  1. redis - Fast, in-memory queue backend

  2. mysql - Persistent storage and database queue

  3. routemq - Main MQTT application

  4. queue-worker-default - Processes jobs from 'default' queue

  5. queue-worker-high - Processes jobs from 'high-priority' queue (faster polling)

  6. queue-worker-emails - Processes jobs from 'emails' queue

Quick Start

Prerequisites

  • Docker 20.10+

  • Docker Compose 2.0+

1. Prepare Environment File

2. Start All Services

3. Verify Deployment

Production Deployment

Environment Configuration

Create a .env file with production settings:

Persistent Data

Data is stored in Docker volumes:

Starting Services

Updating Deployment

Development Setup

For local development, use the minimal development compose file:

Or start everything including the app:

Scaling Workers

Add More Workers for Same Queue

Edit docker-compose.yml to add more worker instances:

Or scale using Docker Compose:

Add Workers for New Queues

To add a worker for a custom queue:

Resource Allocation

Adjust resources per worker based on workload:

Monitoring

View Logs

Resource Usage

Queue Status

Connect to Redis to check queue status:

Check database queue:

Health Checks

All services include health checks:

Service Management

Start/Stop Services

Update Configuration

After changing .env:

Troubleshooting

Workers Not Processing Jobs

Check worker logs:

Common issues:

  • Worker not connected to Redis/MySQL

  • Queue name mismatch

  • Jobs failing during processing

Solutions:

Redis Connection Issues

MySQL Connection Issues

High Memory Usage

Container Won't Start

Database Tables Not Created

Best Practices

1. Use Docker Secrets for Production

Instead of plain text passwords in .env:

2. Regular Backups

Set up automated backups:

3. Log Rotation

Configure log rotation in docker-compose.yml:

4. Monitoring and Alerts

Use Docker health checks and monitoring tools:

5. Resource Limits

Always set resource limits in production:

Example Deployment Scenarios

Scenario 1: Small Deployment (Single Server)

Resources: 1 app + 3 workers + Redis + MySQL

Scenario 2: Medium Deployment (High Load)

Scale workers:

Resources: 1 app + 8+ workers + Redis + MySQL

Scenario 3: Development

Summary

The Docker deployment provides:

  • ✅ Complete stack with Redis and MySQL

  • ✅ Multiple queue workers out of the box

  • ✅ Easy scaling and configuration

  • ✅ Health checks and auto-restart

  • ✅ Resource limits for stability

  • ✅ Development and production setups

For more information, see:

Last updated