mqttv5 - MQTT Command Line Interface
A unified MQTT CLI tool for publishing, subscribing, running a broker, benchmarking, and managing authentication credentials. A single mqttv5 binary covers every common MQTT workflow with consistent flags across all commands, support for TCP/TLS/WebSocket/QUIC transports, and both v5.0 and v3.1.1 protocol versions.
Features
- Single binary: pub, sub, broker, bench, acl, passwd, and scram subcommands
- Interactive prompts for missing arguments
- Input validation with error messages and suggestions
- MQTT v5.0 and v3.1.1 protocol support (
--protocol-version 3.1.1) - Session management: Clean start, session expiry, and persistence
- Will message support: Last will and testament with delay and QoS options
- Automatic reconnection: Opt-in reconnection with exponential backoff
- Multi-transport: TCP, TLS, WebSocket, and QUIC support
- Cross-platform: Linux, macOS, and Windows
Installation
Usage
Publishing Messages
# Basic publish
# With QoS and retain
# Interactive mode (prompts for missing args)
Subscribing to Topics
# Basic subscribe
# Verbose mode shows topic names
# Subscribe for specific message count
# Session persistence and QoS
# Auto-reconnect on disconnect (opt-in)
Running a Broker
The broker uses secure-first authentication. You must choose an authentication mode:
# Anonymous access (for development/testing)
# Password authentication
# SCRAM-SHA-256 authentication
# JWT authentication
# Federated JWT (Google OAuth)
# Federated JWT with trusted roles (Keycloak)
# With ACL authorization
# In-memory storage (no persistence)
Managing Passwords
# Create password file with new user
# Batch mode (password on command line)
# Delete user
Managing ACL Rules
# Add user permissions
# Define roles
# Assign roles to users
# Check permissions
# List rules
Managing SCRAM Credentials
# Create SCRAM credential file with new user
# Batch mode (password on command line)
# Use SCRAM authentication with broker
See Authentication & Authorization Guide for details.
Benchmarking
# Throughput benchmark (default mode)
# Latency benchmark (measures p50/p95/p99)
# Connection rate benchmark
# Custom payload and QoS
# Wildcard subscription testing
CLI Design
The CLI is designed for both interactive exploration and automated scripting. When required arguments are missing, it prompts for them interactively with suggestions and validation. Error messages include contextual hints to guide correction. Long flags have short aliases (-t for --topic, -q for --qos), and all MQTT v5.0 features — including properties, reason codes, and subscription options — are accessible from the command line.
Connection Behavior
By default, the CLI exits immediately when the broker disconnects. This prevents duplicate topic takeover issues when clients reconnect with the same client ID.
Use --auto-reconnect to enable automatic reconnection with exponential backoff. When enabled:
- The library handles reconnection automatically
- Subscriptions are restored based on session state
- The client continues running until Ctrl+C or target message count reached
Examples
Publishing sensor data
Monitoring all home sensors
Testing with retained messages
Advanced MQTT v5.0 Features
# Will messages for device monitoring
# Authentication and session management
# Custom keep-alive and transport options
# WebSocket transport
# QUIC transport (quic:// skips certificate verification)
# QUIC transport with certificate verification (quics:// verifies by default)
# Message expiry and topic alias
# Subscription options (retain handling: 0=send, 1=send if new, 2=don't send)
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.