Add EMQX-compatible delayed publish ($delayed/<seconds>/<topic>)#2245
Open
Romain-OD wants to merge 6 commits into
Open
Add EMQX-compatible delayed publish ($delayed/<seconds>/<topic>)#2245Romain-OD wants to merge 6 commits into
Romain-OD wants to merge 6 commits into
Conversation
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.
Author
|
@dotnet-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.