Skip to content

Add EMQX-compatible delayed publish ($delayed/<seconds>/<topic>)#2245

Open
Romain-OD wants to merge 6 commits into
dotnet:masterfrom
Romain-OD:feature/Delayed-publish-EMQX-compatible-convention
Open

Add EMQX-compatible delayed publish ($delayed/<seconds>/<topic>)#2245
Romain-OD wants to merge 6 commits into
dotnet:masterfrom
Romain-OD:feature/Delayed-publish-EMQX-compatible-convention

Conversation

@Romain-OD
Copy link
Copy Markdown

This PR adds a small opt-in extension package, README.md, that lets the broker hold a message and deliver it later using the EMQX convention:

$delayed/10/sensors/temp       → delivered in 10 seconds
$delayed/1761234567/cron/fire  → delivered at this Unix timestamp

Why
Delayed publish comes up a lot and isn't part of the MQTT spec. Shipping it as an EMQX-compatible topic convention makes it easy for people migrating from EMQX and stays out of the way for everyone else.

How it works
Entirely built on top of existing extension points — no changes to the core broker pipeline:
• Hooks MqttServer.InterceptingPublishAsync, parses the $delayed//... prefix, swallows the original publish (publisher still gets its PUBACK immediately).
• A background worker holds pending messages in a PriorityQueue keyed on due-time and re-injects them via InjectApplicationMessage(InjectedMqttApplicationMessage, CancellationToken) when due.
• Pluggable IDelayedMessageStore — ships with an in-memory default, ready for a SQLite/Redis implementation later.

Introduces MQTTnet.Extensions.DelayedPublish, enabling EMQX-compatible delayed publish support in the broker. Includes core types for scheduling, configuration, and pluggable persistence, with an in-memory store by default. Updates solution and project files and adds documentation.
Implements a background worker to schedule and dispatch delayed MQTT messages. Uses a priority queue for ordering, persists messages, handles expiry, and supports sender identity preservation. Ensures thread safety and proper resource disposal.
Introduce DelayedPublishInterceptor to handle delayed publish topics, validate and schedule messages, and support authorization. Add UseDelayedPublish extension for MqttServer to enable EMQX-compatible delayed publish functionality. Include MIT license headers and required usings.
Added project reference to MQTTnet.Extensions.DelayedPublish. Introduced DelayedPublish_Tests covering delayed dispatch, topic filtering, retain flag, invalid intervals, max delay, and user property preservation.
@Romain-OD
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant