Skip to content

Commit f6d3067

Browse files
authored
Merge pull request #3209 from emqx/r601-message-queue-improvements
update(MQ): Message Queue improvements
2 parents 2484c4a + bbbd6a6 commit f6d3067

File tree

4 files changed

+195
-35
lines changed

4 files changed

+195
-35
lines changed

en_US/cluster-linking/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Configure Cluster Linking
1+
# Cluster Linking User Guide
22

33
This page provides guidelines for configuring and managing the Cluster Linking feature through the EMQX Dashboard, configuration file, and REST API.
44

en_US/cluster-linking/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Quick Start with Cluster Linking
1+
# Cluster Linking Quick Start
22

33
This page provides a quick start guide to setting up cluster linking between two distant EMQX clusters.
44

en_US/message-queue/message-queue-task.md

Lines changed: 101 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
This page walks you through the practical usage of the Message Queue feature in EMQX, from creating queues to configuring their behavior and managing them using the Dashboard, REST API, or configuration files.
44

5-
## Create Message Queue via Dashboard
5+
## Manually Create Message Queue via Dashboard
66

7-
Message Queues must be explicitly declared/created before they can store or dispatch messages.
7+
Message Queues must be explicitly declared/created before they can store or dispatch messages. You can create message queues either manually or automatically. For details about automatic creation, see [Automatically Create Message Queue via Dashboard](#automatically-create-message-queue-via-dashboard).
88

9-
To create a new Message Queue using the EMQX Dashboard:
9+
To create a new Message Queue manually using the EMQX Dashboard:
1010

1111
1. Navigate to **Message Queue** in the left menu.
1212

1313
2. Click the **Create** button on the page.
1414

15-
3. In the **Create Message Queue** dialog:
15+
3. In the **Create Message Queue** dialog, configure the following options:
1616

1717
- **Topic Filter**: Enter the topic or topic filter (e.g., `t/1`). It defines which published messages are enqueued based on topic matching. A queue will collect all messages that match this topic filter.
1818

@@ -26,13 +26,23 @@ To create a new Message Queue using the EMQX Dashboard:
2626

2727
- **Data Retention Period**: Specify how long messages should be retained in the queue. You can set the time unit (e.g., days).
2828

29-
- **Last Value Semantics**: Toggle this switch on if you want new messages with the same queue key to overwrite older messages in the same queue. When enabled, a new message with the same queue key will overwrite any previous, unconsumed message with that key in the queue.
29+
- **Last Value Semantics**: This option is enabled by default. When enabled, a new message with the same queue key will overwrite any previous, unconsumed message with that key in the same queue. This ensures only the most recent message per key is retained. The default key is the client ID of the message publisher.
3030

3131
- **[Queue Key Expression](#queue-key-expression)**: When Last-Value Semantics is enabled, this field defines the expression used to extract the key from each message. The default value is `message.from`, which means the client ID of the message publisher. This field supports configuration using [Variform expressions](../configuration/configuration.md#variform-expressions).
3232

33+
- **Max Shard Message Count**: (Optional) Sets the maximum number of messages allowed in each shard of the queue. You can toggle this setting on and enter a custom value, or leave it disabled to allow unlimited messages (`infinity`). This setting is persisted to durable storage.
34+
35+
- **Max Shard Message Bytes**: (Optional) Sets the maximum total size (in bytes) of messages in each shard of the queue. You can toggle this setting on and enter a value (e.g., `200MB`), or leave it disabled for unlimited size (`infinity`). This setting is persisted to durable storage.
36+
37+
::: tip Performance Note
38+
39+
Queues with size limits may have slower write performance, especially under high throughput conditions.
40+
41+
:::
42+
3343
4. Click **Create** to save the queue.
3444

35-
The new queue will appear in the Message Queue list, showing its topic filter, dispatch strategy, last-value semantics status, and data retention period. You can edit or delete queues using the buttons in the **Actions** column.
45+
The new queue will appear in the Message Queue list, showing its topic filter, dispatch strategy, last-value semantics status, and data retention period. You can edit queue settings or delete queues using the buttons in the **Actions** column.
3646

3747
### Queue Key Expression
3848

@@ -110,23 +120,85 @@ Queue Key Expressions are evaluated against the following message structure:
110120

111121
</details>
112122

123+
## Automatically Create Message Queue via Dashboard
124+
125+
Starting from EMQX 6.0.1, Message Queues can be automatically created when clients subscribe to a `$q/`-prefixed topic. This allows queues to be provisioned dynamically without manual setup.
126+
127+
The queues may be auto-created either as regular queues or last-value semantics queues.
128+
129+
::: tip Note
130+
131+
To ensure proper queue behavior, you can enable either **Auto Create Regular Message Queue** or **Auto Create Last Value Semantics Queue**, but not both at the same time.
132+
133+
:::
134+
135+
### Auto Create Last Value Semantics Queue
136+
137+
This option is turned on by default in the **Message Queue** tab under **MQTT Settings**. It allows EMQX to automatically create queues that support Last-Value Semantics, where only the most recent message with a given key is retained.
138+
139+
1. Navigate to **Management** -> **MQTT Settings** -> **Message Queue** tab.
140+
141+
2. By default, **Enable Auto Create Last Value Semantics Queue** is enabled.
142+
143+
Configure the following:
144+
145+
- **Queue Key Expression**: Required. Defines how to extract a unique key from each message (default: `message.from`).
146+
- **Dispatch Strategy**: Determines how messages are distributed to subscribers (default: `Random`).
147+
- **Data Retention Period**: Specifies how long messages should be retained in the queue.
148+
149+
3. Click **Save Changes**.
150+
151+
When a client subscribes to a topic such as `$q/test`, EMQX will automatically create a last-value semantics queue, which will appear in the **Message Queue** list.
152+
153+
### Auto Create Regular Message Queue
154+
155+
This option can be enabled manually if you prefer regular queues where messages are stored independently and not overwritten.
156+
157+
1. Go to **Management** -> **MQTT Settings** -> **Message Queue** tab.
158+
2. Turn on **Enable Auto Create Regular Message Queue**.
159+
3. Configure the following:
160+
- **Dispatch Strategy**: Determines how messages are distributed to subscribers (default: `Random`).
161+
- **Data Retention Period**: Specifies how long messages should be retained in the queue.
162+
4. Click **Save Changes**.
163+
113164
## Configure Message Queue Settings
114165

115-
This section explains how to configure global settings that apply to all Message Queues in EMQX. These settings control message retention, cleanup intervals, and internal queue behavior. You can configure them via the Dashboard, REST API, or configuration file.
166+
This section explains how to configure global settings that apply to all Message Queues in EMQX. These settings control message retention, cleanup intervals, internal queue behavior, and queue auto-creation behavior. You can configure them via the Dashboard, REST API, or configuration file.
116167

117168
### Dashboard
118169

119170
You can update Message Queue settings directly from the EMQX Dashboard without restarting the broker. This is useful for making changes to system-wide behavior at runtime.
120171

121172
To configure global settings for Message Queues via the Dashboard:
122173

123-
1. Navigate to the **Message Queue** page from the left menu.
124-
2. Click the **Settings** button in the top-right corner of the page.
125-
3. You will be redirected to the **MQTT Settings** -> **Message Queue** tab. In this panel, you can configure the following parameters:
174+
1. Go to **Management** -> **MQTT Settings** -> **Message Queue** tab.
175+
176+
Alternatively, you can click the **Settings** button in the top-right corner of the **Message Queue** page.
177+
178+
2. In the **Message Queue** panel, the following configuration options are available:
179+
- **Enable Message Queue**: The message queue system is enabled by default and cannot be disabled via the Dashboard.
180+
181+
> To disable it, you must modify the configuration file directly.
182+
183+
- **Max Queue Count**: Sets the maximum number of queues that can be created.
184+
126185
- **GC Interval**: The interval at which expired messages are cleaned up from queues. Default is `1` hour.
186+
127187
- **Regular Queue Retention Period**: The maximum duration for which messages are retained in regular queues. Default is `7` days.
188+
128189
- **Find Queue Retry Interval**: When a client subscribes to a `$q/`-prefixed queue topic and the corresponding queue does not yet exist, this setting controls how often the client retries to find the queue. Default is `10` seconds.
129-
4. After making changes, click **Save Changes** to apply the new settings.
190+
191+
- **Auto-Creation Options**: EMQX supports dynamic queue provisioning through auto-creation features.
192+
193+
- **Auto Create Last Value Semantics Queue** (enabled by default): When a client subscribes to a `$q/` topic and no matching queue exists, EMQX will automatically create a queue with Last-Value Semantics enabled.
194+
195+
For details of the settings, see [Auto Create Last Value Semantics Queue](#auto-create-last-value-semantics-queue).
196+
197+
- **Auto Create Regular Message Queue**: Can be enabled as an alternative to the above. When enabled, EMQX will create regular (non-overwriting) queues automatically for `$q/` subscriptions.
198+
199+
For details of the settings, see [Auto Create Regular Message Queue](#auto-create-regular-message-queue).
200+
201+
3. After making changes, click **Save Changes** to apply the new settings.
130202

131203
### REST API
132204

@@ -145,6 +217,8 @@ mq {
145217
gc_interval = 1h
146218
regular_queue_retention_period = 1d
147219
find_queue_retry_interval = 10s
220+
max_queue_count = 100
221+
}
148222
}
149223
```
150224

@@ -156,6 +230,7 @@ mq {
156230
Sets the maximum time that messages are retained in a regular queue. After this period, messages will be purged.
157231
- **`find_queue_retry_interval`**:
158232
Determines how frequently a subscriber retries to locate a queue when subscribing to a `$q/` topic that does not yet exist.
233+
- **`max_queue_count`**: (Optional) Sets the maximum number of queues that can be created.
159234

160235
## Manage Message Queue via REST API
161236

@@ -168,7 +243,7 @@ Create a new message queue by specifying the topic filter and queue properties s
168243
```bash
169244
curl -s -u key:secret -X POST -H "Content-Type: application/json" \
170245
http://localhost:18083/api/v5/message_queues \
171-
-d '{"topic_filter": "t1/#", "is_lastvalue": false}' | jq
246+
-d '{"topic_filter": "t1/#", "is_lastvalue": false, "limits": {"max_shard_message_count": 10000, "max_shard_message_bytes": "200MB"}}' | jq
172247
```
173248

174249
### List All Message Queues
@@ -187,7 +262,7 @@ Update the properties of an existing queue, such as its dispatch strategy:
187262
```bash
188263
curl -s -u key:secret -X PUT -H "Content-Type: application/json" \
189264
http://localhost:18083/api/v5/message_queues/t1%2F%23 \
190-
-d '{"dispatch_strategy": "least_inflight"}' | jq
265+
-d '{"dispatch_strategy": "least_inflight", "limits": {"max_shard_message_count": 5000, "max_shard_message_bytes": "100MB"}}' | jq
191266
```
192267

193268
### Delete a Message Queue
@@ -214,6 +289,17 @@ http://localhost:18083/api/v5/message_queues/t1%2F%23
214289

215290
### What happens when queues exceed capacity?
216291

217-
- Currently, Message Queues are not limited by size (number of messages or total bytes), but they are time-limited via the configured *retention period*.
218-
- Once messages expire (i.e., exceed the retention period), they are no longer eligible for delivery and will be automatically purged by EMQX during regular garbage collection cycles.
292+
Message Queues in EMQX now support multiple types of capacity limits. If any of these limits are reached, EMQX will remove the oldest messages during garbage collection (GC) until the queue size returns within the configured bounds.
293+
294+
- **Time-based limit**: All queues are still subject to the configured *retention period*. Once messages exceed the retention period, they are no longer eligible for delivery and will be automatically purged during GC.
295+
296+
- **Size-based limits**: You can optionally configure per-shard limits on:
297+
298+
- **Max number of messages** (`max_shard_message_count`)
299+
- **Max total size of messages in bytes** (`max_shard_message_bytes`)
300+
301+
These limits are soft and applied during GC, not in real time. Queues may temporarily exceed the configured thresholds between GC cycles.
302+
303+
Note that these limits apply per shard in durable storage. For information on how to configure the number of shards, see [Number of Shards](../durability/managing-replication.md#number-of-shards). In addition, size limits do not account for the [replication factor](../durability/managing-replication.md#replication-factor); the actual physical storage used by a queue will be multiplied by the replication factor.
304+
219305

0 commit comments

Comments
 (0)