MQTT Components and Deployment Architecture
Pub/Sub Client: client application or device identified by a unique client ID that can publish and subscribe to messages.
MQTT Proxy: server-side computing component responsible for MQTT protocol processing, connection session management, and authentication and authorization, stateless to allow rapid scaling.
NameSrv: naming discovery service responsible for routing and addressing based on topics, as well as Broker heartbeat registration.
RocketMQ Broker: server-side component that stores messages, responsible for message sending and receiving, storage, and message models, with support for horizontal scaling.
MQTT Implementation Principle and Architecture
Message Publishing Process
The publishing client establishes a connection with the Proxy. Once connected, it publishes an MQTT message. The Proxy parses and converts the message, then writes it into the RocketMQ Broker for persistence.
Message Storage
After receiving the message, the Broker first persists the message to the Commitlog data file, then creates two indexes based on the topic. The primary topic index is used for event notification, while the multi-level topic index is used for user maintenance of consumption progress.
Message Subscription Process
The subscribing client establishes a connection with the Proxy and specifies the subscribed topic expressions. The Proxy maintains each connection through sessions. When new messages arrive, the notify module broadcasts events to matching sessions, triggering immediate message pop. Additionally, the cache module reduces repeated extraction, improving performance and real-time message delivery.