Skip to content

MQTT Configuration

This page describes every MQTT protocol configuration item. For global/base configuration see Broker Configuration; for other protocols see Kafka Configuration, AMQP Configuration, NATS Configuration.

Overview

All MQTT-related configuration is grouped under the TOML [mqtt_runtime] table (corresponding to the MqttRuntime struct on the Rust side, organized the same way as [kafka_runtime]). This page documents it sub-table by sub-table. The environment-variable override rules are the same as in Broker Configuration, for example:

bash
export ROBUST_MQ_SERVER_MQTT_RUNTIME_SERVER_TCP_PORT=1883

The [mqtt_runtime] table also carries one field directly (not part of any sub-table):

toml
[mqtt_runtime]
broker_worker_threads = 0  # 0 = auto: CPU core count
ConfigurationTypeDefaultDescription
broker_worker_threadsusize0 (auto)Worker threads for the broker-runtime (MQTT connection handling, message delivery hot path); 0 = auto, uses CPU core count

1. MQTT Server Configuration

[mqtt_runtime.server]

MQTT protocol listener port configuration.

toml
[mqtt_runtime.server]
tcp_port = 1883
tls_port = 1885
websocket_port = 8083
websockets_port = 8085
quic_port = 9083
ConfigurationTypeDefaultDescription
tcp_portu321883MQTT over TCP port
tls_portu321885MQTT over TLS port
websocket_portu328083MQTT over WebSocket port
websockets_portu328085MQTT over WebSocket Secure port
quic_portu329083MQTT over QUIC port

2. MQTT Auth & Runtime Configuration

[mqtt_runtime.auth]

toml
[mqtt_runtime.auth]
default_user = "admin"
default_password = "robustmq"
durable_sessions_enable = false
secret_free_login = false
is_self_protection_status = false
ConfigurationTypeDefaultDescription
default_userstring"admin"Default system username
default_passwordstring"robustmq"Default system password
durable_sessions_enableboolfalseEnable durable sessions (false = transient, memory-only, better performance)
secret_free_loginboolfalseWhether to allow passwordless login
is_self_protection_statusboolfalseWhether the node is in self-protection mode (rejects new connections under overload)

MQTT's network threads reuse the shared [broker_network] configuration (see Broker Configuration) — there is no separate [mqtt_runtime.auth.network].


3. MQTT Keep Alive Configuration

[mqtt_runtime.keep_alive]

toml
[mqtt_runtime.keep_alive]
enable = true
default_time = 180
max_time = 3600
default_timeout = 2
ConfigurationTypeDefaultDescription
enablebooltrueEnable Keep Alive heartbeat detection
default_timeu16180Default heartbeat interval (seconds)
max_timeu163600Maximum heartbeat interval (seconds)
default_timeoutu162Number of consecutive timeouts before disconnecting

4. MQTT Protocol Configuration

[mqtt_runtime.protocol]

toml
[mqtt_runtime.protocol]
max_session_expiry_interval = 1800
default_session_expiry_interval = 30
topic_alias_max = 65535
max_packet_size = 10485760
receive_max = 65535
max_message_expiry_interval = 3600
client_pkid_persistent = false
ConfigurationTypeDefaultDescription
max_session_expiry_intervalu321800Maximum session expiry interval (seconds)
default_session_expiry_intervalu3230Default session expiry interval (seconds)
topic_alias_maxu1665535Maximum number of topic aliases
max_packet_sizeu3210485760 (10 MB)Maximum size of a single MQTT packet (bytes)
receive_maxu1665535Maximum number of unacknowledged PUBLISH packets
max_message_expiry_intervalu643600Maximum message expiry interval (seconds)
client_pkid_persistentboolfalseWhether to persist client Packet IDs

5. MQTT Rate Limiting Configuration

[mqtt_runtime.limit]

Cluster- and tenant-level connection/traffic rate limiting configuration.

toml
[mqtt_runtime.limit.cluster]
max_connections_per_node = 10000000
max_connection_rate = 100000
max_topics = 5000000
max_sessions = 50000000
max_publish_rate = 10000

[mqtt_runtime.limit.tenant]
max_connections_per_node = 1000000
max_connection_rate = 10000
max_topics = 500000
max_sessions = 5000000
max_publish_rate = 10000
ConfigurationTypeDescription
max_connections_per_nodeu64Maximum connections per node
max_connection_rateu32Maximum new connection rate per second
max_topicsu64Maximum number of Topics
max_sessionsu64Maximum number of Sessions
max_publish_rateu32Maximum Publish message rate per second

6. MQTT Offline Message Configuration

[mqtt_runtime.offline_message]

Configuration for storing messages while a client is offline.

toml
[mqtt_runtime.offline_message]
enable = true
expire_ms = 0
max_messages_num = 0
ConfigurationTypeDefaultDescription
enablebooltrueEnable offline messages
expire_msu320Offline message expiry time (ms); 0 means never expires
max_messages_numu320Maximum offline messages per client; 0 means unlimited

7. MQTT Connection Flapping Detection

[mqtt_runtime.flapping_detect]

Detects clients that connect/disconnect too frequently ("flapping") and bans them automatically.

toml
[mqtt_runtime.flapping_detect]
enable = false
window_time = 1
max_client_connections = 15
ban_time = 5
ConfigurationTypeDefaultDescription
enableboolfalseEnable connection flapping detection
window_timeu321Detection time window (seconds)
max_client_connectionsu6415Maximum connection attempts within the window
ban_timeu325Ban duration after flapping is triggered (seconds)

8. MQTT Slow Subscribe Detection

[mqtt_runtime.slow_subscribe]

Slow-subscription monitoring for detecting message delivery latency.

toml
[mqtt_runtime.slow_subscribe]
enable = false
record_time = 1000
delay_type = "Whole"
ConfigurationTypeDefaultDescription
enableboolfalseEnable slow-subscription detection
record_timeu641000Slow-subscription record threshold (ms)
delay_typestring"Whole"Latency calculation type: Whole (end-to-end) or Partial

9. MQTT Schema Validation Configuration

[mqtt_runtime.schema]

Message schema validation configuration.

toml
[mqtt_runtime.schema]
enable = true
strategy = "ALL"
failed_operation = "Discard"
echo_log = true
log_level = "info"
ConfigurationTypeDefaultDescription
enablebooltrueEnable schema validation
strategystring"ALL"Validation strategy
failed_operationstring"Discard"What to do on validation failure
echo_logbooltrueWhether to log schema validation
log_levelstring"info"Schema validation log level

Validation strategy:

  • ALL: the message must pass every bound schema
  • Any: the message only needs to pass any one bound schema

Failed operation:

  • Discard: discard the message that failed validation
  • DisconnectAndDiscard: disconnect and discard the message
  • Ignore: ignore the failure and keep processing

10. MQTT System Monitor Configuration

[mqtt_runtime.system_monitor]

System resource monitoring configuration.

toml
[mqtt_runtime.system_monitor]
enable = false
os_cpu_high_watermark = 70.0
os_memory_high_watermark = 80.0
system_topic_interval_ms = 60000
ConfigurationTypeDefaultDescription
enableboolfalseEnable system resource monitoring
os_cpu_high_watermarkf3270.0CPU usage high watermark (%)
os_memory_high_watermarkf3280.0Memory usage high watermark (%)
system_topic_interval_msu6460000System topic metrics publish interval (ms)

Full Example

toml
[mqtt_runtime]
broker_worker_threads = 0

[mqtt_runtime.server]
tcp_port = 1883
tls_port = 1885
websocket_port = 8083
websockets_port = 8085
quic_port = 9083

[mqtt_runtime.auth]
default_user = "admin"
default_password = "your_secure_password"
durable_sessions_enable = false
secret_free_login = false
is_self_protection_status = false

[mqtt_runtime.keep_alive]
enable = true
default_time = 180
max_time = 3600
default_timeout = 2

[mqtt_runtime.protocol]
max_session_expiry_interval = 1800
default_session_expiry_interval = 30
topic_alias_max = 65535
max_packet_size = 10485760
receive_max = 65535
max_message_expiry_interval = 3600
client_pkid_persistent = false

[mqtt_runtime.offline_message]
enable = true
expire_ms = 0
max_messages_num = 0

[mqtt_runtime.flapping_detect]
enable = false
window_time = 1
max_client_connections = 15
ban_time = 5

[mqtt_runtime.slow_subscribe]
enable = false
record_time = 1000
delay_type = "Whole"

[mqtt_runtime.schema]
enable = true
strategy = "ALL"
failed_operation = "Discard"
echo_log = true
log_level = "info"

[mqtt_runtime.system_monitor]
enable = false
os_cpu_high_watermark = 70.0
os_memory_high_watermark = 80.0
system_topic_interval_ms = 60000

Further Reading

🎉 既然都登录了 GitHub,不如顺手给我们点个 Star 吧!⭐ 你的支持是我们最大的动力 🚀