Skip to content

Commit 8d03403

Browse files
committed
Update dir.yaml and sync zh and ja folders
1 parent 775d53f commit 8d03403

23 files changed

+1386
-0
lines changed

dir.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,14 @@
878878
children:
879879
- message-queue/message-queue-task
880880
- message-queue/message-queue-quick-start
881+
- title_en: Message Stream
882+
title_cn: 消息流
883+
title_ja: Message Queue
884+
path: message-stream/message-stream-concept
885+
collapsed: true
886+
children:
887+
- message-stream/message-stream-task
888+
- message-stream/message-stream-quick-start
881889
- title_en: MQTT over QUIC
882890
title_cn: MQTT over QUIC
883891
title_ja: MQTT over QUIC
141 KB
Loading
127 KB
Loading
417 KB
Loading
330 KB
Loading
443 KB
Loading
276 KB
Loading
281 KB
Loading
274 KB
Loading
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Message Stream
2+
3+
EMQX 6.1 introduces the Message Stream, a streaming and replay feature that extends MQTT’s real-time publish/subscribe model with persistent, replayable message streams. It enables Kafka-like streaming capabilities while preserving MQTT semantics.
4+
5+
This page provides a complete overview of the Message Stream feature in EMQX, covering its design motivation, key concepts, internal architecture, message flow, and real-world application scenarios.
6+
7+
## What Is a Message Stream?
8+
9+
A Message Stream is a logical collection of MQTT messages that automatically collects messages matching a topic filter during its lifetime. It stores matching messages durably and allows clients to replay historical data by subscribing to a stream-specific topic.
10+
11+
## Why Use Message Stream?
12+
13+
MQTT is optimized for real-time messaging, but it has inherent limitations:
14+
15+
- Messages are typically delivered only to online subscribers.
16+
- Historical data replay is not natively supported.
17+
- Reprocessing past data requires external systems.
18+
- Maintaining an ordered, replayable message history is difficult.
19+
20+
Message Stream extends MQTT with durable message storage and replay. It allows consumers to read historical messages and retrieve the latest state of devices without changing how MQTT clients publish or subscribe.
21+
22+
## Message Stream Key Concepts
23+
24+
- **Message Stream**
25+
26+
A logical resource identified by an MQTT topic filter and managed with an explicit lifecycle. While active, it continuously stores matching messages within configured time or size limits. Stored messages can be replayed by subscribing consumers, without requiring any changes on the publishing side.
27+
28+
- **Topic Filter**
29+
30+
An MQTT topic filter, such as `sensors/+/data`, that determines which published messages are captured into a stream. Only matching messages are ingested, and a single message may belong to multiple streams.
31+
32+
- **Stream Subscription**
33+
34+
A special MQTT subscription used to consume messages from a stream. Clients subscribe using the `$s/<timestamp>/<topic_filter>` format. The timestamp specifies the replay starting point. Stream subscriptions operate independently of regular MQTT subscriptions and are delivered through the External Subscription mechanism.
35+
36+
- **Key Expression**
37+
38+
A user-defined expression evaluated on each incoming message to extract a key. The expression may reference message content or metadata. The extracted key determines per-key ordering and enables Last-Value semantics, where newer messages overwrite older ones with the same key.
39+
40+
## Message Streams Architecture
41+
42+
Message Streams are implemented as a standalone EMQX application that is loosely coupled with the broker core and reuses existing infrastructure. Integration with EMQX is achieved through internal hooks and the External Subscription framework.
43+
44+
::: tip
45+
46+
External Subscription is an EMQX mechanism that connects external message sources (messages originating outside the live MQTT publish path) to MQTT client sessions, allowing those messages to be delivered to MQTT clients through standard MQTT subscriptions without changing client behavior.
47+
48+
:::
49+
50+
### Main Components
51+
52+
- **Streams Registry**: Manages the lifecycle of Message Streams and maintains stream metadata and indexes. It uses a Mnesia table to efficiently look up streams by topic filter.
53+
- **Streams Message Database**: Provides durable storage for stream messages and is built on top of EMQX [Durable Storage](../design/durable-storage.md#design-for-durable-storage). It persists messages, enforces retention limits, applies Last-Value semantics when enabled, and supports efficient message retrieval until messages expire according to retention policies.
54+
- **Streams ExtSub Handler**: Integrates Message Streams with MQTT client sessions. It retrieves messages from Durable Storage and delivers them to subscribing clients through the External Subscription framework.
55+
56+
### Message Stream Data Flow Diagram
57+
58+
The following diagram shows the data flow between the Message Stream components:
59+
60+
```ascii
61+
+-----------------------+
62+
| Message Stream DS DB |
63+
+-----------------------+
64+
^ ^
65+
| |
66+
| |
67+
| | Subscription on topic data
68+
| |
69+
| +-------------------------------------+ +--------------------------------+
70+
| | | Client Connection |
71+
| | (Subscribing channel) |
72+
| Write transaction | | +----------------------------+ |
73+
| | | | ExtSub | |
74+
| | | | +------------------------+ | |
75+
| | | | | Streams ExtSub Handler | | |
76+
+---------------------------+ +----->| | | |
77+
| Client Connection |
78+
|(Publishing channel) | | | +----------------|-------+ | |
79+
| | | +------------------|---------+ |
80+
+---------------------------+ +--------------------|-----------+
81+
| |
82+
| Stream |
83+
| lookup V
84+
| +--------------------------+
85+
| Fast stream lookup in the index | Streams Registry |
86+
+----------------------------------------------------------------> | |
87+
+--------------------------+
88+
```
89+
90+
### Publishing Flow
91+
92+
1. A client publishes a message to an MQTT topic.
93+
2. A Message Stream hook is triggered to process the publication.
94+
3. The hook queries the Streams Registry to identify streams whose topic filters match the message topic.
95+
4. For each matching stream, the message is written to the stream and persisted in Durable Storage.
96+
97+
### Subscribing and Consuming Flow
98+
99+
1. A client subscribes to a stream topic (`$s/<timesstamp>/<topic_filter>`).
100+
2. The External Subscription framework handles the subscription and initializes a Streams ExtSub handler for the stream topic.
101+
3. The handler retrieves messages from Durable Storage according to the specified timestamp and retention rules.
102+
4. Retrieved messages are passed to the External Subscription framework.
103+
5. The ExtSub application delivers messages to the client via standard MQTT delivery.
104+
105+
## Message Stream Core Features
106+
107+
Message Stream provides a set of core capabilities that define how messages are stored, ordered, retained, and delivered for replay-based consumption.
108+
109+
- **Timestamp-Based Replay**
110+
111+
Message streams support replay starting from a specified timestamp. Consumers choose the timestamp when subscribing. Messages published before the timestamp are skipped.
112+
113+
- **Retention**
114+
115+
The stream’s retention policy limits the message replay. Messages are retained for a limited time or size. Expired messages are removed automatically, regardless of whether they have been consumed.
116+
117+
- **Per-Key Ordering**
118+
119+
Message streams do not guarantee a single global delivery order. Messages that share the same key are always delivered in the order in which they were published. Messages with different keys may be delivered in any order.
120+
121+
- **Last-Value Semantics**
122+
123+
A stream may enable Last-Value semantics. Messages with the same key overwrite earlier messages. Only the most recent message per key is retained. Messages without a resolved key are stored normally.
124+
125+
- **MQTT-Native Delivery**
126+
127+
Stream messages are delivered using standard MQTT mechanisms. Publishers do not need to change their behavior. Message delivery to subscribers is integrated through External Subscription.
128+
129+
## Typical Use Cases
130+
131+
- **Historical Data Replay**: Reprocess past MQTT events for debugging or new business logic.
132+
- **Time-Series Analysis**: Store and replay sensor data for analytics and predictive maintenance.
133+
- **Event Sourcing**: Persist all state changes as an immutable event log.
134+
- **IoT Digital Twins**: Maintain the latest state of physical devices in digital form.
135+
- **Configuration Synchronization**: Ensure devices always receive the most recent configuration.
136+
137+
## Next Steps
138+
139+
Now that you understand the Message Stream fundamentals, explore how to put them into practice:
140+
141+
- [Create and Configure a Stream](./message-stream-task.md): Learn how to declare streams via Dashboard or REST API, and set last-value semantics and retention policies.
142+
- [Quick Start Tutorial](./message-stream-quick-start.md): Follow a step-by-step guide using MQTTX to simulate real-world publisher and subscriber scenarios.

0 commit comments

Comments
 (0)