HUB
Sign inSign up
broker logo

connectmqcom/broker

By connectmqcom

•Updated 2 days ago

Connectmq.com MQTT broker for BYOC: run in your own AWS, Azure, Google Cloud or Docker host

Image
Message queues
Internet of things
0

153

connectmqcom/broker repository overview

⁠ConnectMQ Broker: Bring Your Own Cloud (BYOC)

Run a ConnectMQ MQTT broker node inside your own cloud account (AWS, Azure, Google Cloud or any Docker host) while ConnectMQ manages authentication, ACLs, quotas and usage reporting.

Your message traffic stays on infrastructure you control. Only control-plane calls (broker login, client authentication, heartbeats, usage reports) go to the ConnectMQ Central API.

  • MQTT 3.1.1 and 5.0 over TCP, TLS, WebSocket and secure WebSocket
  • MQTT 5 shared subscriptions, isolated per tenant
  • Per-tenant topic isolation, quotas, rate limiting, flood protection and IP blacklisting
  • Sparkplug B and ISA-95 / Unified Namespace detection, with automatic Sparkplug B to ISA-95 conversion
  • Multi-arch: linux/amd64 and linux/arm64 (AWS Graviton, Azure Ampere, Google Axion/Tau T2A)
  • Runs as a non-root user (UID 1654)

⁠How BYOC works

 Your devices / apps                    Your cloud account                      ConnectMQ
 ───────────────────   MQTT / TLS   ┌──────────────────────────┐   HTTPS   ┌──────────────────┐
  sensors, PLCs,     ─────────────▶ │  connectmqcom/broker     │ ────────▶ │  Central API     │
  backends, browsers ◀───────────── │  (container)             │ ◀──────── │  auth, ACL,      │
                                    └──────────────────────────┘           │  quotas, billing │
                                     messages never leave here             └──────────────────┘
  1. On startup the broker calls https://brokerapi.connectmq.com and logs in with its Broker ID and Broker Secret Key.
  2. When a client connects, the broker asks the Central API to check the username and password and to return the tenant's ACLs and quotas.
  3. Publishes and subscriptions are handled locally. Payloads are not sent to ConnectMQ.

⁠Before you start

You needWhere to get it
Broker IDYour ConnectMQ BYOC subscription (dashboard), or ConnectMQ support
Broker Secret KeyIssued together with the Broker ID. Keep it in a secret store.
Outbound HTTPS (443) to brokerapi.connectmq.comAllow it in your firewall / NAT / egress rules
Inbound ports for MQTT clientsSee Ports⁠
(optional) a DNS name and TLS certificatee.g. mqtt.example.com, from Let's Encrypt, ACM, Key Vault or Certificate Manager

Order matters: docker run [options: -e, -p, -v ...] connectmqcom/broker:<tag>. Options written after the image name are passed to the broker as arguments, not as environment variables.

The container exits with code 1 if the secret is missing, the Central API is unreachable, or the credentials are rejected. Check docker logs first.

One broker ID per running instance. A broker node keeps sessions, retained messages and subscriptions in memory. Run exactly one container per Broker ID, and request another Broker ID for each additional node.


⁠Ports

Container portProtocolNotes
1883MQTT over TCPPlain text. Expose it only on private networks, or behind a TLS-terminating load balancer.
8883MQTT over TLSActive only when a certificate is mounted
8083MQTT over WebSocketPath /mqtt (or /)
8084MQTT over secure WebSocketActive only when a certificate is mounted

You can serve TLS in the container (mount a certificate) or at a layer-4 load balancer (forward 8883 → 1883 and 8084 → 8083). Both work. The load-balancer option lets your cloud renew certificates automatically.

Use layer-4 (TCP/TLS) load balancers and keep the client's source IP. Quotas, flood protection and IP bans work on the client's IP. If every client shows up with the load balancer's IP, a single misbehaving client can get everyone banned. Do not put the broker behind HTTP/L7 load balancers (ALB, Application Gateway, Cloud Run, HTTP(S) LB), because they do not carry raw MQTT.

⁠Environment variables

VariableDefaultDescription
BROKER_IDrequiredBroker ID issued by ConnectMQ
BROKER_SECRET_KEYrequiredBroker secret issued by ConnectMQ
CENTRAL_API_URLhttps://brokerapi.connectmq.comChange only if ConnectMQ tells you to
PUBLIC_BROKER_ENABLEDtrueAllow anonymous clients under the public quota. Set false for BYOC.
MQTT_PORT1883MQTT TCP port inside the container
MQTTS_PORT8883MQTT TLS port
MQTT_WS_PORT8083WebSocket port
MQTT_WSS_PORT8084Secure WebSocket port
SSL_CERTIFICATE_PATH/app/certs/broker.pemPEM (certificate chain + private key) or PFX
SSL_CERTIFICATE_PASSWORD(empty)Password for a PFX file

⁠Volumes

PathContents
/app/logsHourly rolling logs per scope (broker, public, each tenant), kept 14 days, plus the persistent IP blacklist. Optional. Logs also go to stdout.
/app/certsYour TLS certificate (mount read-only)
/app/broker.json(optional) Full configuration override: quotas, overload protection, flood protection, payload logging

⁠Sizing

WorkloadvCPUMemory
Up to ~1,000 connections / low traffic0.51 GB
Up to ~10,000 connections24 GB
Larger4+8 GB+ (contact ConnectMQ)

⁠1. Docker / Docker Compose (any VM or on-premises server)

docker run -d --name connectmq-broker --restart unless-stopped \
  -p 1883:1883 -p 8883:8883 -p 8083:8083 -p 8084:8084 \
  -e BROKER_ID=my-broker-01 \
  -e BROKER_SECRET_KEY='<your-secret>' \
  -e PUBLIC_BROKER_ENABLED=false \
  -v connectmq-logs:/app/logs \
  -v /etc/connectmq/certs:/app/certs:ro \
  connectmqcom/broker:1.0.0

docker-compose.yml:

services:
  connectmq-broker:
    image: connectmqcom/broker:1.0.0
    restart: unless-stopped
    environment:
      BROKER_ID: my-broker-01
      BROKER_SECRET_KEY: ${BROKER_SECRET_KEY}   # from .env, never commit it
      PUBLIC_BROKER_ENABLED: "false"
    ports: ["1883:1883", "8883:8883", "8083:8083", "8084:8084"]
    volumes:
      - connectmq-logs:/app/logs
      - ./certs:/app/certs:ro
volumes:
  connectmq-logs:

TLS with Let's Encrypt: combine the chain and key into one PEM that the container user (UID 1654) can read:

cat /etc/letsencrypt/live/mqtt.example.com/fullchain.pem \
    /etc/letsencrypt/live/mqtt.example.com/privkey.pem > /etc/connectmq/certs/broker.pem
chown 1654:1654 /etc/connectmq/certs/broker.pem && chmod 400 /etc/connectmq/certs/broker.pem
docker restart connectmq-broker   # after each renewal

⁠2. AWS

1. Store the secret in AWS Secrets Manager:

aws secretsmanager create-secret --name connectmq/broker-secret --secret-string '<your-secret>'

2. Register a task definition (task-def.json). Use "cpuArchitecture": "ARM64" for Graviton:

{
  "family": "connectmq-broker",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "1024",
  "memory": "2048",
  "runtimePlatform": { "operatingSystemFamily": "LINUX", "cpuArchitecture": "X86_64" },
  "executionRoleArn": "arn:aws:iam::<ACCOUNT_ID>:role/ecsTaskExecutionRole",
  "containerDefinitions": [{
    "name": "broker",
    "image": "connectmqcom/broker:1.0.0",
    "essential": true,
    "portMappings": [
      { "containerPort": 1883, "protocol": "tcp" },
      { "containerPort": 8083, "protocol": "tcp" }
    ],
    "environment": [
      { "name": "BROKER_ID", "value": "my-broker-01" },
      { "name": "PUBLIC_BROKER_ENABLED", "value": "false" }
    ],
    "secrets": [
      { "name": "BROKER_SECRET_KEY",
        "valueFrom": "arn:aws:secretsmanager:<REGION>:<ACCOUNT_ID>:secret:connectmq/broker-secret" }
    ],
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "/ecs/connectmq-broker",
        "awslogs-region": "<REGION>",
        "awslogs-stream-prefix": "broker",
        "awslogs-create-group": "true"
      }
    }
  }]
}
aws ecs create-cluster --cluster-name connectmq
aws ecs register-task-definition --cli-input-json file://task-def.json

The execution role needs secretsmanager:GetSecretValue on the secret.

3. Create a Network Load Balancer with ip target groups. The NLB terminates TLS with an ACM certificate:

NLB listenerProtocolTarget group (container port)
1883 (optional, private only)TCPtg-mqtt → 1883
8883TLS (ACM cert)tg-mqtt → 1883
8084TLS (ACM cert)tg-ws → 8083
aws elbv2 create-target-group --name tg-mqtt --protocol TCP --port 1883 \
  --target-type ip --vpc-id <VPC_ID> --health-check-protocol TCP
# keep the real client IP (quotas and bans depend on it)
aws elbv2 modify-target-group-attributes --target-group-arn <TG_MQTT_ARN> \
  --attributes Key=preserve_client_ip.enabled,Value=true

Do the same for tg-ws on port 8083.

4. Create the service with exactly one task:

aws ecs create-service --cluster connectmq --service-name connectmq-broker \
  --task-definition connectmq-broker --desired-count 1 --launch-type FARGATE \
  --deployment-configuration minimumHealthyPercent=0,maximumPercent=100 \
  --network-configuration "awsvpcConfiguration={subnets=[<SUBNET_A>,<SUBNET_B>],securityGroups=[<SG_ID>],assignPublicIp=ENABLED}" \
  --load-balancers "targetGroupArn=<TG_MQTT_ARN>,containerName=broker,containerPort=1883" \
                   "targetGroupArn=<TG_WS_ARN>,containerName=broker,containerPort=8083"

minimumHealthyPercent=0 makes sure two tasks with the same Broker ID never run at the same time during a deployment.

Security group: allow inbound 1883/8083 from the internet (client IPs are preserved, so the traffic arrives from client addresses) or only from your device CIDRs, and allow outbound 443. If the tasks run in private subnets, give them a NAT gateway so they can reach brokerapi.connectmq.com.

5. DNS: create a Route 53 alias mqtt.example.com → NLB. Clients connect to mqtts://mqtt.example.com:8883 or wss://mqtt.example.com:8084/mqtt.

⁠Option B: a single EC2 instance

Launch Amazon Linux 2023 (x86 or Graviton), install Docker, and follow the Docker section⁠. Attach an Elastic IP and open ports 1883/8883/8083/8084 in the security group.

sudo dnf install -y docker && sudo systemctl enable --now docker

Not supported: App Runner and Lightsail container services (HTTP only), and Application Load Balancer (L7).


⁠3. Microsoft Azure

⁠Option A: Azure Container Instances (simplest)
az group create -n connectmq-rg -l westeurope

az container create -g connectmq-rg -n connectmq-broker \
  --image connectmqcom/broker:1.0.0 \
  --os-type Linux --cpu 1 --memory 2 \
  --ports 1883 8883 8083 8084 \
  --ip-address Public --dns-name-label my-connectmq \
  --restart-policy Always \
  --environment-variables BROKER_ID=my-broker-01 PUBLIC_BROKER_ENABLED=false \
  --secure-environment-variables BROKER_SECRET_KEY='<your-secret>'

The broker is then reachable at my-connectmq.westeurope.azurecontainer.io. Client source IPs are preserved.

TLS in ACI: deploy with YAML and mount the certificate as a secret volume. Secret values are base64-encoded:

apiVersion: '2021-10-01'
location: westeurope
name: connectmq-broker
type: Microsoft.ContainerInstance/containerGroups
properties:
  osType: Linux
  restartPolicy: Always
  ipAddress:
    type: Public
    dnsNameLabel: my-connectmq
    ports: [{port: 1883, protocol: TCP}, {port: 8883, protocol: TCP},
            {port: 8083, protocol: TCP}, {port: 8084, protocol: TCP}]
  containers:
  - name: broker
    properties:
      image: connectmqcom/broker:1.0.0
      resources: {requests: {cpu: 1, memoryInGB: 2}}
      ports: [{port: 1883}, {port: 8883}, {port: 8083}, {port: 8084}]
      environmentVariables:
      - {name: BROKER_ID, value: my-broker-01}
      - {name: PUBLIC_BROKER_ENABLED, value: "false"}
      - {name: BROKER_SECRET_KEY, secureValue: <your-secret>}
      volumeMounts:
      - {name: certs, mountPath: /app/certs, readOnly: true}
  volumes:
  - name: certs
    secret:
      broker.pem: <base64 of fullchain+privkey PEM>
az container create -g connectmq-rg --file aci.yaml
⁠Option B: Azure Container Apps (TCP ingress)

TCP ingress requires a Container Apps environment with your own VNet:

az containerapp env create -g connectmq-rg -n connectmq-env -l westeurope \
  --infrastructure-subnet-resource-id <SUBNET_ID>

az containerapp create -g connectmq-rg -n connectmq-broker --environment connectmq-env \
  --image connectmqcom/broker:1.0.0 --cpu 1 --memory 2Gi \
  --min-replicas 1 --max-replicas 1 \
  --ingress external --transport tcp --target-port 1883 --exposed-port 1883 \
  --secrets broker-secret='<your-secret>' \
  --env-vars BROKER_ID=my-broker-01 PUBLIC_BROKER_ENABLED=false BROKER_SECRET_KEY=secretref:broker-secret

To expose 8083/8883/8084 as well, add them as additionalPortMappings in the app's ingress configuration. Keep max-replicas at 1.

⁠Option C: Azure VM

Create an Ubuntu VM (or an Ampere Dpsv5 VM for arm64), install Docker, and follow the Docker section⁠. Open the ports in the Network Security Group.

Not supported: Application Gateway / Front Door (L7). Use Azure Load Balancer (L4) if you need a load balancer in front.

Secrets: store BROKER_SECRET_KEY and the certificate in Azure Key Vault, and reference them from Container Apps or your deployment pipeline.


⁠4. Google Cloud

gcloud compute firewall-rules create connectmq-mqtt \
  --allow tcp:1883,tcp:8883,tcp:8083,tcp:8084 --target-tags connectmq

gcloud compute instances create connectmq-broker \
  --zone europe-west1-b --machine-type e2-standard-2 \
  --image-family cos-stable --image-project cos-cloud \
  --tags connectmq \
  --metadata-from-file user-data=cloud-init.yaml

cloud-init.yaml (Container-Optimized OS):

#cloud-config
write_files:
- path: /etc/systemd/system/connectmq.service
  permissions: '0644'
  content: |
    [Unit]
    Description=ConnectMQ Broker
    Wants=network-online.target docker.service
    After=network-online.target docker.service
    [Service]
    ExecStartPre=-/usr/bin/docker rm -f connectmq-broker
    ExecStart=/usr/bin/docker run --name connectmq-broker \
      -p 1883:1883 -p 8883:8883 -p 8083:8083 -p 8084:8084 \
      -e BROKER_ID=my-broker-01 -e PUBLIC_BROKER_ENABLED=false \
      --env-file /var/lib/connectmq/secret.env \
      -v /var/lib/connectmq/logs:/app/logs \
      -v /var/lib/connectmq/certs:/app/certs:ro \
      connectmqcom/broker:1.0.0
    ExecStop=/usr/bin/docker stop connectmq-broker
    Restart=always
    [Install]
    WantedBy=multi-user.target
runcmd:
- mkdir -p /var/lib/connectmq/logs /var/lib/connectmq/certs
- chown -R 1654:1654 /var/lib/connectmq
- systemctl daemon-reload
- systemctl enable --now connectmq.service

Put BROKER_SECRET_KEY=<your-secret> into /var/lib/connectmq/secret.env (mode 600), or fetch it from Secret Manager at boot with gcloud secrets versions access latest --secret=connectmq-broker-secret. Reserve a static external IP for the VM.

⁠Option B: Google Kubernetes Engine
kubectl create secret generic connectmq --from-literal=BROKER_SECRET_KEY='<your-secret>'
kubectl create secret generic connectmq-certs --from-file=broker.pem=./broker.pem   # optional
apiVersion: apps/v1
kind: Deployment
metadata: {name: connectmq-broker}
spec:
  replicas: 1                     # one pod per Broker ID
  strategy: {type: Recreate}      # never run two pods with the same Broker ID
  selector: {matchLabels: {app: connectmq-broker}}
  template:
    metadata: {labels: {app: connectmq-broker}}
    spec:
      securityContext: {runAsUser: 1654, runAsGroup: 1654, fsGroup: 1654}
      containers:
      - name: broker
        image: connectmqcom/broker:1.0.0
        env:
        - {name: BROKER_ID, value: my-broker-01}
        - {name: PUBLIC_BROKER_ENABLED, value: "false"}
        envFrom: [{secretRef: {name: connectmq}}]
        ports:
        - {containerPort: 1883}
        - {containerPort: 8883}
        - {containerPort: 8083}
        - {containerPort: 8084}
        resources:
          requests: {cpu: 500m, memory: 1Gi}
          limits: {memory: 2Gi}
        readinessProbe: {tcpSocket: {port: 1883}, periodSeconds: 15}
        volumeMounts: [{name: certs, mountPath: /app/certs, readOnly: true}]
      volumes:
      - name: certs
        secret: {secretName: connectmq-certs, optional: true}
---
apiVersion: v1
kind: Service
metadata: {name: connectmq-broker}
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local    # keep the real client IP
  selector: {app: connectmq-broker}
  ports:
  - {name: mqtt,  port: 1883, targetPort: 1883}
  - {name: mqtts, port: 8883, targetPort: 8883}
  - {name: ws,    port: 8083, targetPort: 8083}
  - {name: wss,   port: 8084, targetPort: 8084}

The same manifest works on Amazon EKS and Azure AKS.

Not supported: Cloud Run (HTTP only, one port, request timeouts) and external HTTP(S) Load Balancing (L7).


⁠Verify the deployment

docker logs connectmq-broker        # or CloudWatch / Log Analytics / Cloud Logging

A healthy start looks like this:

Central API is HEALTHY (attempt 1/3).
Broker login SUCCESSFUL! Session token received (...)
MQTT TCP listener bound to port 1883.

Test with a ConnectMQ user:

mosquitto_sub -h mqtt.example.com -p 8883 --capath /etc/ssl/certs \
  -u '<user>' -P '<password>' -t 'demo/#' -v
mosquitto_pub -h mqtt.example.com -p 8883 --capath /etc/ssl/certs \
  -u '<user>' -P '<password>' -t 'demo/hello' -m 'hi'

⁠Troubleshooting

Log messageCause / fix
BROKER_SECRET_KEY is not setThe variable never reached the container. Put every -e option before the image name (anything after the image is passed to the app as arguments). Do not use -e BROKER_SECRET_KEY without a value unless it is set in your shell.
Central Authentication API ... UNREACHABLEOutbound HTTPS to brokerapi.connectmq.com is blocked. Check NAT, firewall and proxy.
Invalid broker secret keyWrong Broker ID / secret pair. Check your ConnectMQ dashboard.
No SSL/TLS certificate foundNo certificate at /app/certs/broker.pem, so 8883/8084 are off. Mount one, or terminate TLS at the load balancer.
Clients disconnected within 3 sThey opened a socket without sending MQTT CONNECT. This is expected for port scanners.
All clients banned at onceThe load balancer hides client IPs. Enable client IP preservation (see Ports⁠).

⁠Updating

docker pull connectmqcom/broker:<new-version>
docker rm -f connectmq-broker && docker run ...   # same arguments, new tag

On ECS, Container Apps or GKE, update the image tag in the task definition or deployment. Pin a specific version in production instead of latest.

⁠Tags

  • 1.0.0: first BYOC release
  • latest: newest stable release

⁠Support

⁠Connect every device. Run zero brokers.

A private, secure managed MQTT broker in minutes — with live dashboards, rules and alerts built in. Connect sensors, machines, vehicles and apps without running a single server.

Tag summary

Content type

Image

Digest

sha256:e805f7ca8…

Size

88.2 MB

Last updated

2 days ago

docker pull connectmqcom/broker