You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
4
5
-
## Create Message Queue via Dashboard
5
+
## Manually Create Message Queue via Dashboard
6
6
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).
8
8
9
-
To create a new Message Queue using the EMQX Dashboard:
9
+
To create a new Message Queue manually using the EMQX Dashboard:
10
10
11
11
1. Navigate to **Message Queue** in the left menu.
12
12
13
13
2. Click the **Create** button on the page.
14
14
15
-
3. In the **Create Message Queue** dialog:
15
+
3. In the **Create Message Queue** dialog, configure the following options:
16
16
17
17
-**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.
18
18
@@ -26,13 +26,23 @@ To create a new Message Queue using the EMQX Dashboard:
26
26
27
27
-**Data Retention Period**: Specify how long messages should be retained in the queue. You can set the time unit (e.g., days).
28
28
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.
30
30
31
31
-**[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).
32
32
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
+
33
43
4. Click **Create** to save the queue.
34
44
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.
36
46
37
47
### Queue Key Expression
38
48
@@ -110,23 +120,85 @@ Queue Key Expressions are evaluated against the following message structure:
110
120
111
121
</details>
112
122
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.
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
+
113
164
## Configure Message Queue Settings
114
165
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.
116
167
117
168
### Dashboard
118
169
119
170
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.
120
171
121
172
To configure global settings for Message Queues via the Dashboard:
122
173
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
+
126
185
-**GC Interval**: The interval at which expired messages are cleaned up from queues. Default is `1` hour.
186
+
127
187
-**Regular Queue Retention Period**: The maximum duration for which messages are retained in regular queues. Default is `7` days.
188
+
128
189
-**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.
130
202
131
203
### REST API
132
204
@@ -145,6 +217,8 @@ mq {
145
217
gc_interval = 1h
146
218
regular_queue_retention_period = 1d
147
219
find_queue_retry_interval = 10s
220
+
max_queue_count = 100
221
+
}
148
222
}
149
223
```
150
224
@@ -156,6 +230,7 @@ mq {
156
230
Sets the maximum time that messages are retained in a regular queue. After this period, messages will be purged.
157
231
-**`find_queue_retry_interval`**:
158
232
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.
159
234
160
235
## Manage Message Queue via REST API
161
236
@@ -168,7 +243,7 @@ Create a new message queue by specifying the topic filter and queue properties s
168
243
```bash
169
244
curl -s -u key:secret -X POST -H "Content-Type: application/json" \
- 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.
0 commit comments