Skip to content

Multi-Protocol Architecture

RobustMQ supports five protocols — MQTT, Kafka, NATS, AMQP, and mq9 — within a single Broker process. All protocols share the same runtime, storage layer, and cluster coordination components.


Layered Structure

Multi-Protocol Layered Architecture


Layer Responsibilities

Network Layer

Listens on per-protocol ports, handles connection establishment and TLS handshake, and delivers byte streams to the protocol layer for parsing. Five transport modes are supported: TCP, TLS, WebSocket, WebSocket Secure, and QUIC.

Protocol Layer

Protocol-specific encoding and decoding logic. Parses byte streams into protocol frames and serializes protocol frames back into byte streams. Contains no business logic.

ProtocolStatus
MQTT 3.1 / 3.1.1 / 5.0Production-ready
KafkaIn development
NATSIn development
AMQPPlanned
mq9In development

Protocol Logic Layer

Protocol-specific business modules that handle session management, subscriptions, consumer groups, and other protocol-defined behaviors. Crates for different protocols have no dependencies on each other.

Common Message Logic Layer

Business capabilities shared across all protocols, called by each protocol logic layer:

CapabilityDescription
Message expiryCleans up messages according to per-Topic TTL configuration
Delayed publishDelivers messages at a specified future time
AuthenticationUsername/password, TLS certificate, and token verification
ACLRead/write access control at the resource level
Schema validationValidates message payload format
MetricsPrometheus metrics collection

Storage Adapter

Abstracts each protocol's storage concepts (Topic / Partition / Queue) into a unified Shard, and routes operations to the appropriate storage backend. The Broker has no awareness of the underlying storage type or distribution. See StorageAdapter-Architecture.md.


Shared Runtime

All protocols share:

  • Meta Service connection: Cluster coordination and metadata reads/writes use a shared gRPC connection pool
  • Storage Engine connection: Message reads and writes share a single storage layer; data is written once
  • Raft state machine: Cluster consistency is provided by the same Multi-Raft implementation
  • Metrics collection: Prometheus metrics are exposed on a single shared port

Protocol Isolation Principle

Protocol logic layers have no crate-level dependencies on each other and evolve independently. Protocol-specific concepts (MQTT QoS, Kafka Consumer Group, NATS Subject) do not leak into other layers. Shared capabilities (authentication, Schema validation, metrics) are provided as separate crates and imported on demand by each protocol.

As a result, adding a new protocol does not touch existing protocol code, and changes to one protocol do not affect others.

Cross-Protocol Message Routing

Each protocol currently stores messages in its own Shards; there is no automatic routing between protocols. Cross-protocol message sharing is implemented at the Shard level through the Storage Adapter: consumers from different protocols can subscribe to the same Shard (i.e., the same Topic/Partition mapping) to consume the same data.


Scope of Adding a New Protocol

Adding a new protocol requires implementing:

  1. Protocol layer: Encoding/decoding logic to parse protocol frames
  2. Protocol logic layer: Protocol-specific session, subscription, and consume business logic
  3. Network layer registration: Register the protocol handler on the corresponding port

The following do not need to be modified: Storage Adapter, Storage Engine, Meta Service, or the common logic layer.

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