Skip to content

feat(rumqttd): expose retain flag on local LinkTx publish#1050

Open
podarok wants to merge 1 commit into
bytebeamio:mainfrom
EnergyCitizen:feat/linktx-publish-with-retain
Open

feat(rumqttd): expose retain flag on local LinkTx publish#1050
podarok wants to merge 1 commit into
bytebeamio:mainfrom
EnergyCitizen:feat/linktx-publish-with-retain

Conversation

@podarok
Copy link
Copy Markdown

@podarok podarok commented May 1, 2026

Type of change

New feature (non-breaking change which adds functionality).

What this fixes

local::LinkTx::publish and try_publish hardcode retain: false (rumqttd/src/link/local.rs:223,242), which prevents an in-process publisher from seeding the broker's retained store. Anyone embedding rumqttd and wanting to serve a snapshot to late subscribers on first SUBSCRIBE has had to either:

  • spin up a loopback rumqttc client and publish-with-retain over the wire (extra dependency, extra connect/CONNACK race window), or
  • wait for the next live publish to land before retained delivery kicks in.

What this PR does

Add two thin wrappers that take an explicit retain flag:

pub fn publish_with_retain<S, V>(&mut self, topic: S, payload: V, retain: bool) -> Result<usize, LinkError>
pub fn try_publish_with_retain<S, V>(&mut self, topic: S, payload: V, retain: bool) -> Result<usize, LinkError>

The existing publish and try_publish keep their previous behaviour (retain: false) and now delegate, so the change is fully backwards-compatible.

Use case

ec-ui-light (a Tauri desktop app that ships an embedded rumqttd to replay captured Victron MQTT fixtures) needs to seed the retained store with a small set of dashboard-critical topics (system/0/Serial, system/0/Dc/Battery/Soc, system/0/Ac/Grid/...) before the WebView's MQTT client subscribes. Doing this through a loopback rumqttc client raced the WebView's first SUBSCRIBE; calling publish_with_retain directly on a freshly-built LinkTx populates the retained store synchronously and the race goes away.

Checklist

  • Formatted with cargo fmt
  • CHANGELOG entry added under [Unreleased]
  • Backwards-compatible — existing callers see no behaviour change

`local::LinkTx::publish` and `try_publish` hardcode `retain: false`,
which prevents in-process callers from seeding the retained store
with snapshot-class topics. Embedded-broker setups that want to
serve a state snapshot to late subscribers on first SUBSCRIBE
currently have to spin up a loopback rumqttc client to publish
with retain over the wire, or wait for the next live publish.

Add `publish_with_retain` and `try_publish_with_retain` that take
an explicit retain flag. Existing `publish` / `try_publish` keep
the previous behaviour and now delegate, so the change is fully
backwards-compatible.
@tekjar
Copy link
Copy Markdown
Contributor

tekjar commented May 1, 2026

@giridher-art Can you review this?

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.

2 participants