Delayed Publish
Delayed publish is an extended MQTT feature supported by EMQX. When a client publishes a message to EMQX with the topic prefix $delayed/{DelayInteval}
, it triggers the delayed publish feature. The messages will be published after a period of time predefined by the user.
The specific format of the delay-publish topic is as below:
$delayed/{DelayInterval}/{TopicName}
$delayed
: Messages prefixed with$delay
will be treated as messages that need to be delayed. The delay interval is determined by the content of the next topic level.{DelayInterval}
: Specify the time interval for delaying the publishing of this MQTT message with the unit of second. The maximum allowed interval is 4294967 seconds. If{DelayInterval}
cannot be parsed as an integer number, EMQX will discard the message and the client will not receive any information.{TopicName}
: The topic name of the MQTT message.
Example:
$delayed/15/x/y
: Publish MQTT message to the topicx/y
after 15 seconds$delayed/60/a/b
: Publish MQTT message to the topica/b
after 1 minute$delayed/3600/$SYS/topic
: Publish MQTT message to the topic$SYS/topic
after 1 hour
Configure Delayed Publish via Dashboard
Open EMQX Dashboard. In the left navigation menu, click Management-> Delayed Publish.
On the Delayed Publish page, you can configure as follows:
- Enable: Enable or disable delayed publish. By default, it is enabled.
- Max Delayed Messages: The max number of delayed messages.
- If you select Unlimited from the drop-down list, you cannot specify the number.
- If you select Custom from the drop-down list, you can specify the number.
Try Delayed Publish with MQTTX Client
Prerequisite
- Basic publishing and subscribing operations using MQTTX Client
Start the MQTTX Client. Click the New Connection to create an MQTT connection named
Demo
.- The localhost
127.0.0.1
is used as an example in this demonstration.
TIP
For detailed instructions on creating an MQTT connection, see MQTTX Client.
- The localhost
Create another MQTT connection. Configure it as a subscriber.
Select the connection named
Demo
in the Connections pane. Type the topic name$delayed/10/x/y
in the topic text box and type the message asDelayed Message
.$delayed
: Indicates it is a delay message.10
: Indicates the delayed interval is 10 seconds.x/y
: Indicates the topic name of the message.
Select the connection named
Subscriber
. Click the New Subscription button to create a subscription. Typex/y
in the Topic textbox to subscribe to this topic.Select the connection named
Demo
in the Connections pane. Click the send button to send theDelayed Message
with topic$delayed/10/x/y
.Wait for 10 seconds. You will see the connection named
Subscriber
receive the delayed message after 10 seconds.
Try Delayed Publish with MQTTX CLI
Prerequisite
- Basic publishing and subscribing operations using MQTTX CLI
Create a new connection as a subscriber and subscribe to the topic
t/1
.mqttx sub -t t/1 -v
Open a new window in the terminal for the client as publisher. Use the following command to send a delayed message. The subscriber will receive the message after 5 seconds.
mqttx pub -t "\$delayed/5/t/1" -m "Hello Delayed msg"