gobridge

Runbook: Persistent MQTT Managed-Filter Migration

Applies to: removal or replacement of MQTT wildcard/shared filters on a Persistent or Exclusive session.

Start here when:

Why a held delivery needs settling

MQTT does not require a broker to redistribute an unacknowledged shared QoS 1/2 delivery after disconnect. A broker may pin it to the persistent session and replay it only to the same ClientID, and it may also deliver messages it queued for the filter while the bridge was disconnected. MQTT 5 gives a client no way to hand such a delivery back: a PUBACK with an error reason code ends it like a successful one. Held unacknowledged, it is resent after every reconnect and occupies one Receive Maximum slot; enough of them stop all traffic to the session.

Either way, a delivery whose topic a still-desired filter also covers is not settled as a removed filter’s delivery. When a replacement overlaps the removed filter (for example $share/old/a/# replaced by $share/new/a/#), that delivery is live traffic for the new filter: GoBridge keeps it and delivers it to the route once the removed filter is forgotten. It is not dead-lettered, and without a dead-letter store it no longer fails the migration closed.

Replay settlement lasts until the current connection’s replay-grace window (unmatched_grace, counted from the connection coming up) ends; a delivery does not restart the window.

Prepare a no-buffer cutover

  1. Record the old canonical broker URL, ClientID, session mode/expiry, managed store identity, exact filters (including the complete $share/group/filter), and handlers.
  2. Stop publishers or otherwise stop new ingress matching filters being removed.
  3. Let handlers and durable outbound work drain. Keep a restorable copy of the old configuration.
  4. Apply the desired configuration. Wait for Full only after exact UNSUBSCRIBE, reconnect, and the unmatched_grace no-replay verification window complete.

Removing or renaming an entire durable session, or changing its broker URL or client ID, is an ordinary live reload: retiring the old session ends its broker session, with its subscriptions and queued messages (broker identity changes on live reload). Drain what you need from the old session first. Existing sessions with no ledger baseline must first be seeded with every exact filter or migrated under maintenance as documented in the MQTT transport reference.

Dead-lettered deliveries: inspect, then redrive or purge

Each record has error code SUBSCRIPTION_REMOVED, category permanent, the session ID, the route ID of the session’s single ingress route (empty when no single route rides on the session: none or several), and source_id, which is the session ID; it scopes the record to the session, so two sessions’ deliveries with the same message ID stay separate records. The dead-letter store also keeps the removed filter as the record’s address; the Admin API views do not show the address, but they show the filter as extra_info.subscription on a record with redrive_mode auto.

Each record written, or found already written, counts one DLQEntries with category subscription_removed, tagged route_id with the record’s route when it names one and with no route_id otherwise. So the DLQEntries alarms fire for these records. The delivery never reached a route, so the route conservation law in Monitoring leaves this category out.

Adding the filter back redrives them by itself. When the removed filter is added back on the same persistent or exclusive session (you roll the configuration back, or enable the filter again) and the broker grants it, GoBridge redrives that filter’s records that are younger than stores.dlq.auto_redrive_window (default 24h) through the session’s route, and deletes each one once the route has delivered it (automatic redrive). It does not redrive records older than the window, records with an empty route_id, records filed under a route that was since renamed, or any record while the session has no single ingress route: redrive those by hand as below. Nor does it redrive a record whose session a live reload removed, renamed or gave a new broker URL or client ID, or a record written before ADR 0024: the record names the session and the managed subscription identity it had, and no running session has both any more. The redrive waits until the runtime is ready, and that wait is runtime-wide: every session of the runtime must be connected and subscribed, so an unrelated session that is down postpones it.

A record whose automatic redrive failed stays in the store. The bridge logs a warning, automatic redrive failed; the DLQ record is kept, with the record’s dlq_id and the error. It also writes a dlq.redrive.auto audit record with outcome failure, but only when the runtime has an audit logger: the AWS profile gives it one, the reference binary cmd/gobridge does not. When a failure stops the pass, the records after it are not attempted and get no log line or audit record of their own; they wait for the next time the filter is added back, or for you. An admin redrive you start while an automatic pass is running is not serialized with it, so one record can be redriven twice (a duplicate, as ADR 0015 allows, never a loss). Redrive by hand after the pass has ended: the bridge logs automatic redrive pass finished at debug level, with the counts of records redriven and failed.

  1. Find the records. The Admin API cannot filter by error code, so list the permanent entries and select on the response. Page with offset while has_more is true.

    curl -s -H "X-API-Key: $API_KEY" \
      "http://localhost:8080/api/v1/admin/dlq/messages?category=permanent&limit=1000" \
      | jq '.messages[] | select(.error_code == "SUBSCRIPTION_REMOVED" and .session_id == "<session-id>")'
    
  2. Inspect. GET /api/v1/admin/dlq/messages/{id} returns one record with its payload. That read is audited as dlq.read_payload, because a payload can hold personal data or secrets. Decide per record whether the message must still be delivered.
  3. Redrive a message that must still be delivered: POST /api/v1/admin/dlq/redrive with its IDs. Redrive re-injects it into the record’s route_id through that route’s current processors and bindings, and deletes the record only after the inject is confirmed. A record with an empty route_id, or whose route no longer exists, fails with route or binding not found and is kept; purge it or re-inject the payload by another route.
  4. Purge a message that is no longer wanted: POST /api/v1/admin/dlq/delete with its IDs.

Warning: deleting a record destroys the only copy of the message, and it cannot be undone. Delete by ID. Do not use POST /api/v1/admin/dlq/purge: it deletes the entire dead-letter store, including records from every other route.

The request and response contracts are in the Admin API reference; a walkthrough is in Scenario 7: DLQ with HTTP API Management.

If the session keeps failing its reconcile with a transient UNAVAILABLE error, the dead-letter writes are failing: the store is down, or too slow to finish the writes of one replay-verification pass within one reconcile_timeout, counted from the first write. Fix the store. The session retries by itself and the held deliveries stay unacknowledged until a write succeeds; do not restore the old configuration for this.

Without a dead-letter store: restore, drain, retry

  1. Keep publishers stopped. Stop the failed migration process. For Exclusive mode, wait at least the remaining lease TTL and verify that no replacement owner is active; the failed process intentionally does not release its lease.
  2. Do not edit or empty stores.managed_subscriptions, change ClientID, set clean_start, expire/delete the broker session, or acknowledge the replay by another path. Those actions can destroy evidence or lose the delivery.
  3. Start exactly one fresh runtime with the old broker/session identity, the same managed store, and the exact old filters and handlers.
  4. Wait for the pinned delivery to be processed through its normal handler. Confirm source settlement and any outbox/downstream drain. Confirm the old broker-session backlog is empty; do not infer this merely from readiness.
  5. Stop the restored runtime cleanly. Reapply the desired configuration and retry removal. A successful retry removes exact wildcard and shared filters, reconnects, completes its no-replay window, and reaches Full.
  6. Resume publishers and verify a peer receives new shared traffic and MQTTRouterUnmatchedDropped did not increase for the migrated session.

If the retry fails closed again, repeat restore/drain/retry; do not bypass the ledger. A managed-store outage or a reconciliation deadline shorter than the verification window is also fail-closed uncertainty and must be corrected before retry. With a dead-letter store configured, a later migration dead-letters a pinned replay instead, and this procedure is not needed for it.