All Products
Search
Document Center

ApsaraMQ for MQTT:Clear subscriptions for a topic

Last Updated:Mar 11, 2026

By default, ApsaraMQ for MQTT keeps a client's subscriptions active after it disconnects and delivers queued offline messages when the client reconnects. If your messages have freshness requirements or you need to retire inactive subscribers, enable subscription cleanup to automatically remove subscriptions after a client has been offline for a specified period.

How subscription cleanup works

ApsaraMQ for MQTT tracks each client's last heartbeat. With automatic subscription cleanup enabled for a topic, ApsaraMQ for MQTT compares the current time against the client's last heartbeat. If the offline duration meets or exceeds the configured Cleanup Cycle, the system deletes the subscription between that client and the topic.

After a subscription is cleared:

  • The client stops receiving new offline messages from that topic.

  • The client can still receive offline messages that were generated *before* the cleanup and remain within their validity period.

Offline message delivery also depends on the QoS and cleanSession parameters. For details, see Terms.

Important

Subscription changes affect instance billing. For details, see Billing overview.

Configure subscription cleanup

Procedure

Warning

Enabling subscription cleanup prevents clients from receiving offline messages. Proceed with caution.

  1. Log on to the ApsaraMQ for MQTT console and click Instances in the left-side navigation pane.

  2. In the top navigation bar, select a region. On the Instances page, click the instance ID to open the Instance Details page.

  3. In the left-side navigation pane, click Topics. Find the target topic and choose More > Subscription Cleanup in the Actions column.

  4. In the Configure Automatic Cleanup Cycle panel, configure the following settings and click OK.

    SettingDescription
    Enable Automatic Subscription CleanupSet to Yes to activate automatic cleanup, or No to keep subscriptions persistent.
    Cleanup CycleThe offline threshold for subscription removal. A subscription is cleared when the time since the client's last heartbeat meets or exceeds this value.

Result

After saving, confirm the cleanup cycle in the Subscription Cleanup Cycle column of the topic list.