MQTT Component and Deployment Architecture
Pub/Sub Client: Refers to a client application or device uniquely identified by a Client ID, capable of publishing or subscribing to messages.
MQTT Proxy: A server-side computing component responsible for MQTT protocol processing, connection session management, authentication and authorization, and is stateless for rapid scaling.
NameSrv: Naming discovery service, responsible for routing addressing by Topic and Broker heartbeat registration.
RocketMQ Broker: A server-side component that stores messages, responsible for message sending and receiving, storage, and message model, and supports horizontal scaling.
MQTT Implementation Principle and Architecture
Publish Message Process
The publishing client establishes a connection with the Proxy. Upon success, 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 a message, the Broker first persists the message to the Commitlog data file, then creates two indexes based on the subject. The primary topic index is used for event notification, while the multi-level topic index is used for user maintenance of consumption progress.
Subscribe to Messages Process
The subscribing client establishes a connection with the Proxy and specifies the subscribed topic expression. The Proxy maintains each connection through a session. When new messages arrive, the notify module broadcasts notifications to matching sessions to immediately pop messages. Additionally, the cache module reduces repeated extraction, enhancing performance and message real-timeness.